質問するログイン新規登録

質問編集履歴

1

本文の追記

2018/04/12 00:53

投稿

kazoogon
kazoogon

スコア281

title CHANGED
File without changes
body CHANGED
@@ -53,4 +53,83 @@
53
53
  ]);
54
54
  }
55
55
  ```
56
- よろしくお願いいたします。
56
+ よろしくお願いいたします。
57
+
58
+
59
+ **質問を受けての追記**
60
+ ---
61
+ mts10806さん、質問ありがとうございます。
62
+
63
+ **参考にしたurl**
64
+ https://blog.capilano-fw.com/?p=261(laravel,axios使用での一通りの流れを参考にした)
65
+ https://www.yoheim.net/blog.php?q=20170801(axiosの詳細はこちらで)
66
+
67
+ **試してみたこと**
68
+ 上のサイトを参考にして、js側に引数に情報をいれた(こちらはこれで間違っていないと思われる)
69
+ ```
70
+ methods:{
71
+ empty:function(rowIndex,colIndex){
72
+ this.rows[rowIndex].columns[colIndex].isActive = ! this.rows[rowIndex].columns[colIndex].isActive;
73
+ const data = { rowIndex : rowIndex, colIndex : colIndex };
74
+
75
+ //console.logで値が取れていることは確認済
76
+ console.log(data.colIndex);
77
+ console.log(data.rowIndex);
78
+
79
+ this.$http.post('/ajax/reservation_calender/from_teacher', data)
80
+ .then(function(response){
81
+ // 成功したとき
82
+
83
+ alert("成功!!!");//テストのため
84
+ }).catch(function(error){
85
+ // 失敗したとき
86
+
87
+ alert('送信が失敗しました。');//テストのため
88
+ });
89
+ }
90
+ }
91
+ ```
92
+
93
+ server側にてとりあえず、引数関係なし+数値をそのまま入れてDBに挿入
94
+  →DBに値は入った
95
+ ```
96
+ public function store()
97
+ {
98
+ $time_id = 1;
99
+ $date_id = 1;
100
+ $teacher_id = 1;
101
+ $user_id = 1;
102
+
103
+ $reservation_calender = new Reservation_calender();
104
+ $reservation_calender->time_id = $time_id;
105
+ $reservation_calender->teacher_id = $teacher_id;
106
+ $reservation_calender->user_id = $user_id;
107
+ $reservation_calender->save();
108
+
109
+ return response()->json([
110
+ 'result' => true
111
+ ]);
112
+ }
113
+ ```
114
+
115
+ 他のcontrollerの書き方を真似て引数を受け取り、DBに入れようとする
116
+  →ajax送信失敗
117
+ ```
118
+ public function store(data $data)
119
+ {
120
+ $time_id = $data[rowIndex];
121
+ $date_id = $data[colIndex];
122
+ $teacher_id = 1;
123
+ $user_id = 1;
124
+
125
+ $reservation_calender = new Reservation_calender();
126
+ $reservation_calender->time_id = $time_id;
127
+ $reservation_calender->teacher_id = $teacher_id;
128
+ $reservation_calender->user_id = $user_id;
129
+ $reservation_calender->save();
130
+
131
+ return response()->json([
132
+ 'result' => true
133
+ ]);
134
+ }
135
+ ```