回答編集履歴

1

追記

2016/11/22 07:07

投稿

yambejp
yambejp

スコア114839

test CHANGED
@@ -9,3 +9,71 @@
9
9
  仮にajaxでpostしたあとにページの遷移をするだけなら
10
10
 
11
11
  location.hrefでデータを送らない遷移ではいけないのでしょうか?
12
+
13
+
14
+
15
+ # 追記
16
+
17
+ とりあえずajaxの部分はこうしてください
18
+
19
+ ```javascript
20
+
21
+ <script>
22
+
23
+ $(function(){
24
+
25
+ $('form').on('submit',function(){
26
+
27
+ var data = {};
28
+
29
+ $(this).find('input[name]').each(function(){
30
+
31
+ data[$(this).prop('name')]=$(this).val();
32
+
33
+ });
34
+
35
+ console.log(JSON.stringify(data));
36
+
37
+ $.ajax({
38
+
39
+ type: $('form').attr('method'),
40
+
41
+ url: $('form').attr('action'),
42
+
43
+ dataType: 'text',
44
+
45
+ data: data,
46
+
47
+ success:function(d){
48
+
49
+ console.log(d);
50
+
51
+ },
52
+
53
+ });
54
+
55
+ return false;
56
+
57
+ });
58
+
59
+ });
60
+
61
+
62
+
63
+ </script>
64
+
65
+ <form method="post" action="xxx.php">
66
+
67
+ <input type="text" name="aaa" value="123">
68
+
69
+ <input type="hidden" name="bbb" value="xyz">
70
+
71
+ <input type="submit" value="go">
72
+
73
+ </form>
74
+
75
+
76
+
77
+
78
+
79
+ ```