回答編集履歴

1

調整

2018/08/01 03:31

投稿

yambejp
yambejp

スコア114883

test CHANGED
@@ -1 +1,63 @@
1
1
  $.ajaxでdataを指定してないからでしょう
2
+
3
+
4
+
5
+ # sample
6
+
7
+ postが前提であればデータ渡しはformdataがよいでしょう
8
+
9
+ ```javascript
10
+
11
+ <script>
12
+
13
+ $(function () {
14
+
15
+ $('#form').on('submit',function(e){
16
+
17
+ var fd = new FormData($('#form').get(0));
18
+
19
+ e.preventDefault();
20
+
21
+ $.ajax({
22
+
23
+ "url": 'ajax.php',
24
+
25
+ "type": "POST",
26
+
27
+ "dataType": "html",
28
+
29
+ "data":fd,
30
+
31
+ "cache":false,
32
+
33
+ "processData": false,
34
+
35
+ "contentType": false,
36
+
37
+ }).done(function(data){
38
+
39
+ console.log(data);
40
+
41
+ });
42
+
43
+ });
44
+
45
+ });
46
+
47
+ </script>
48
+
49
+
50
+
51
+ <form id="form" name="search" action="" method="POST">
52
+
53
+ <input type="radio" id="color01" name="color" value="red" checked><label for="color01">赤</label>
54
+
55
+ <input type="radio" id="color02" name="color" value="blue"><label for="color02">青</label>
56
+
57
+ <button class="submit" value="検索">検索</button>
58
+
59
+ </form>
60
+
61
+ ```
62
+
63
+ 一応サブミットしたときにバックグラウンドで処理してあります