質問編集履歴

6

2018/11/16 15:06

投稿

oroshitaruuuuu
oroshitaruuuuu

スコア25

test CHANGED
File without changes
test CHANGED
@@ -46,196 +46,186 @@
46
46
 
47
47
 
48
48
 
49
- #### CDN
49
+ #### ソースコード
50
+
50
-
51
+ ```Controller/Sample/Sample1.php
52
+
53
+
54
+
51
- ```script
55
+ <?php
56
+
52
-
57
+ namespace App\Controller\Sample;
58
+
59
+
60
+
61
+ use App\Controller\AppController;
62
+
63
+ use Cake\ORM\TableRegistry;
64
+
65
+ use Cake\Core\Exception\Exception;
66
+
67
+ use Cake\Error\ExceptionRenderer;
68
+
69
+
70
+
71
+ /**
72
+
73
+ * Sample1 Controller
74
+
75
+ */
76
+
77
+ class Sample1Controller extends AppController
78
+
79
+ {
80
+
81
+ /**
82
+
83
+ * Initialize method
84
+
85
+ */
86
+
87
+ public function initialize()
88
+
89
+ {
90
+
91
+ parent::initialize();
92
+
53
- <script src="//ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
93
+ $this->viewBuilder()->setLayout('Sample/sample1');
94
+
95
+ $this->loadComponent('RequestHandler');
96
+
97
+ }
98
+
99
+
100
+
101
+ /**
102
+
103
+ * Index method
104
+
105
+ */
106
+
107
+ public function index()
108
+
109
+ {
110
+
111
+
112
+
113
+ //省略
114
+
115
+
116
+
117
+ $this->set(compact('data1'));
118
+
119
+ }
120
+
121
+
122
+
123
+ /**
124
+
125
+ * Loading method
126
+
127
+ * @return $test テストデータ
128
+
129
+ */
130
+
131
+ public function loading()
132
+
133
+ {
134
+
135
+ $this->autoRender = false;
136
+
137
+ if ($this->request->is('ajax')) {
138
+
139
+ // 送られてきたリクエストデータを取得する
140
+
141
+ $test = $this->request->getData('test');
142
+
143
+
144
+
145
+ // 必要な処理を実装していく
146
+
147
+
148
+
149
+ // 戻り値を返却する
150
+
151
+
152
+
153
+ echo json_encode($test);
154
+
155
+ }
156
+
157
+ }
158
+
159
+ }
160
+
161
+
54
162
 
55
163
  ```
56
164
 
57
165
 
58
166
 
59
- #### ソースコード
60
-
61
- ```Cakephp
62
-
63
-
64
-
65
- <?php
66
-
67
- namespace App\Controller\Sample;
68
-
69
-
70
-
71
- use App\Controller\AppController;
72
-
73
- use Cake\ORM\TableRegistry;
74
-
75
- use Cake\Core\Exception\Exception;
76
-
77
- use Cake\Error\ExceptionRenderer;
78
-
79
-
80
-
81
- /**
82
-
83
- * Sample1 Controller
84
-
85
- */
86
-
87
- class Sample1Controller extends AppController
88
-
89
- {
90
-
91
- /**
92
-
93
- * Initialize method
94
-
95
- */
96
-
97
- public function initialize()
98
-
99
- {
100
-
101
- parent::initialize();
102
-
103
- $this->viewBuilder()->setLayout('Sample/sample1');
104
-
105
- $this->loadComponent('RequestHandler');
106
-
107
- }
108
-
109
-
110
-
111
- /**
112
-
113
- * Index method
114
-
115
- */
116
-
117
- public function index()
118
-
119
- {
120
-
121
-
122
-
123
- //省略
124
-
125
-
126
-
127
- $this->set(compact('data1'));
128
-
129
- }
130
-
131
-
132
-
133
- /**
134
-
135
- * Loading method
136
-
137
- * @return $test テストデータ
138
-
139
- */
140
-
141
- public function loading()
142
-
143
- {
144
-
145
- $this->autoRender = false;
146
-
147
- if ($this->request->is('ajax')) {
148
-
149
- // 送られてきたリクエストデータを取得する
150
-
151
- $test = $this->request->getData('test');
152
-
153
-
154
-
155
- // 必要な処理を実装していく
156
-
157
-
158
-
159
- // 戻り値を返却する
160
-
161
-
162
-
163
- echo json_encode($test);
164
-
165
- }
166
-
167
- }
167
+ ```webroot/js/sample1.js
168
+
169
+
170
+
171
+ $("button").on("click",function(){
172
+
173
+ var test = "test";
174
+
175
+ execAjax(test);
176
+
177
+ });
178
+
179
+
180
+
181
+ function execAjax(test){
182
+
183
+ $.ajax({
184
+
185
+ type: "POST",
186
+
187
+ url: "/App/Sample/Sample1/loading",
188
+
189
+ data: {
190
+
191
+ "test" : test,
192
+
193
+ },
194
+
195
+ })
196
+
197
+ // Ajaxリクエストが成功した時発動
198
+
199
+ .done(function(response){
200
+
201
+ alert("成功");
202
+
203
+ alert(response);
204
+
205
+ })
206
+
207
+ // Ajaxリクエストが失敗した時発動
208
+
209
+ .fail(function(XMLHttpRequest, textStatus, errorThrown){
210
+
211
+ alert("失敗");
212
+
213
+ console.log("ajax通信に失敗しました");
214
+
215
+ console.log("XMLHttpRequest : " + XMLHttpRequest.status);
216
+
217
+ console.log("textStatus : " + textStatus);
218
+
219
+ console.log("errorThrown : " + errorThrown.message);
220
+
221
+ });
168
222
 
169
223
  }
170
224
 
171
-
172
-
173
225
  ```
174
226
 
175
227
 
176
228
 
177
- ```js
178
-
179
-
180
-
181
- $("button").on("click",function(){
182
-
183
- var test = "test";
184
-
185
- execAjax(test);
186
-
187
- });
188
-
189
-
190
-
191
- function execAjax(test){
192
-
193
- $.ajax({
194
-
195
- type: "POST",
196
-
197
- url: "/App/Sample/Sample1/loading",
198
-
199
- data: {
200
-
201
- "test" : test,
202
-
203
- },
204
-
205
- })
206
-
207
- // Ajaxリクエストが成功した時発動
208
-
209
- .done(function(response){
210
-
211
- alert("成功");
212
-
213
- alert(response);
214
-
215
- })
216
-
217
- // Ajaxリクエストが失敗した時発動
218
-
219
- .fail(function(XMLHttpRequest, textStatus, errorThrown){
220
-
221
- alert("失敗");
222
-
223
- console.log("ajax通信に失敗しました");
224
-
225
- console.log("XMLHttpRequest : " + XMLHttpRequest.status);
226
-
227
- console.log("textStatus : " + textStatus);
228
-
229
- console.log("errorThrown : " + errorThrown.message);
230
-
231
- });
232
-
233
- }
234
-
235
- ```
236
-
237
-
238
-
239
229
  #### 追記
240
230
 
241
231
  - cakephpのインストールと設定

5

追記

2018/11/16 15:06

投稿

oroshitaruuuuu
oroshitaruuuuu

スコア25

test CHANGED
File without changes
test CHANGED
@@ -233,3 +233,15 @@
233
233
  }
234
234
 
235
235
  ```
236
+
237
+
238
+
239
+ #### 追記
240
+
241
+ - cakephpのインストールと設定
242
+
243
+ 参考サイト
244
+
245
+ [https://qiita.com/YoshikiNakamura/items/bcceaaa3d064a08233c1](https://qiita.com/YoshikiNakamura/items/bcceaaa3d064a08233c1)
246
+
247
+ [https://www.ritolab.com/entry/59](https://www.ritolab.com/entry/59)

4

文章修正

2018/11/16 13:02

投稿

oroshitaruuuuu
oroshitaruuuuu

スコア25

test CHANGED
File without changes
test CHANGED
@@ -12,6 +12,8 @@
12
12
 
13
13
  jquery 3.1.1
14
14
 
15
+ MAMP 5.0.1
16
+
15
17
 
16
18
 
17
19
  #### できないこと

3

文章修正

2018/11/16 12:45

投稿

oroshitaruuuuu
oroshitaruuuuu

スコア25

test CHANGED
File without changes
test CHANGED
@@ -78,13 +78,7 @@
78
78
 
79
79
  /**
80
80
 
81
- * Review Controller
81
+ * Sample1 Controller
82
-
83
- *
84
-
85
- *
86
-
87
- *
88
82
 
89
83
  */
90
84
 

2

文章修正

2018/11/16 11:08

投稿

oroshitaruuuuu
oroshitaruuuuu

スコア25

test CHANGED
File without changes
test CHANGED
@@ -58,8 +58,6 @@
58
58
 
59
59
  ```Cakephp
60
60
 
61
- Controller/Sample/Sample1/loading
62
-
63
61
 
64
62
 
65
63
  <?php

1

文章修正

2018/11/16 11:05

投稿

oroshitaruuuuu
oroshitaruuuuu

スコア25

test CHANGED
File without changes
test CHANGED
@@ -64,7 +64,7 @@
64
64
 
65
65
  <?php
66
66
 
67
- namespace App\Controller\Netflix;
67
+ namespace App\Controller\Sample;
68
68
 
69
69
 
70
70
 
@@ -86,11 +86,11 @@
86
86
 
87
87
  *
88
88
 
89
- * @method \App\Model\Entity\Review[]|\Cake\Datasource\ResultSetInterface paginate($object = null, array $settings = [])
89
+ *
90
90
 
91
91
  */
92
92
 
93
- class ReviewController extends AppController
93
+ class Sample1Controller extends AppController
94
94
 
95
95
  {
96
96