回答編集履歴

1

ajax

2022/06/23 00:42

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -19,3 +19,30 @@
19
19
  },$v);
20
20
  print json_encode($v);
21
21
  ```
22
+ # $.ajax処理
23
+ ```javascript
24
+ const post_data = {
25
+ comment : 'hello',
26
+ is_official: false
27
+ };
28
+ const data = {
29
+ action : 'test_ajax',
30
+ post_data : JSON.stringify(post_data),
31
+ }
32
+ $.ajax({
33
+ url : 'sample.php',
34
+ type : 'POST',
35
+ dataType: 'json',
36
+ data : data
37
+ }).done(function(res) {
38
+ console.log(res);
39
+ });
40
+ ```
41
+ //sample.php
42
+ PHP側で何をしたいかわからないのでとりあえず
43
+ おくられてきたjsonデータをそのまま表示
44
+ ```PHP
45
+ <?PHP
46
+ $post_data=filter_input(INPUT_POST,"post_data",FILTER_DEFAULT);
47
+ print $post_data;
48
+ ```