回答編集履歴
4
うけとり
test
CHANGED
@@ -181,3 +181,29 @@
|
|
181
181
|
```
|
182
182
|
|
183
183
|
のような処理です。
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
# 受け取り側
|
188
|
+
|
189
|
+
※仮にpost処理だとします
|
190
|
+
|
191
|
+
```PHP
|
192
|
+
|
193
|
+
<?PHP
|
194
|
+
|
195
|
+
$name=filter_input(INPUT_POST,"name");
|
196
|
+
|
197
|
+
if(!is_null($name){
|
198
|
+
|
199
|
+
print htmlspecialchars($name);
|
200
|
+
|
201
|
+
exit;
|
202
|
+
|
203
|
+
}
|
204
|
+
|
205
|
+
?>
|
206
|
+
|
207
|
+
HTML部分
|
208
|
+
|
209
|
+
```
|
3
POST
test
CHANGED
@@ -30,7 +30,7 @@
|
|
30
30
|
|
31
31
|
$('.submit button').on('click',function(e){
|
32
32
|
|
33
|
-
e.preventDefault();/*
|
33
|
+
e.preventDefault();/* typo調整*/
|
34
34
|
|
35
35
|
$.ajax({
|
36
36
|
|
@@ -123,3 +123,61 @@
|
|
123
123
|
<div class="submit"><button type="button" name="mode" value="confirm"><img src="images/check.png" alt="送信"></button>
|
124
124
|
|
125
125
|
```
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
# POST処理
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
```javascript
|
134
|
+
|
135
|
+
$(function(){
|
136
|
+
|
137
|
+
$('.submit button').on('click',function(e){
|
138
|
+
|
139
|
+
e.preventDefault();
|
140
|
+
|
141
|
+
$.ajax({
|
142
|
+
|
143
|
+
url: '/sample/index',
|
144
|
+
|
145
|
+
type: 'POST',
|
146
|
+
|
147
|
+
data: new FormData($('#f1').get(0)),
|
148
|
+
|
149
|
+
dataType: 'text',
|
150
|
+
|
151
|
+
cache:false,
|
152
|
+
|
153
|
+
processData: false,
|
154
|
+
|
155
|
+
contentType: false,
|
156
|
+
|
157
|
+
}).done(function(data){
|
158
|
+
|
159
|
+
console.log(data);
|
160
|
+
|
161
|
+
}).fail(function(xhr,err){
|
162
|
+
|
163
|
+
console.log(err);
|
164
|
+
|
165
|
+
});
|
166
|
+
|
167
|
+
});
|
168
|
+
|
169
|
+
});
|
170
|
+
|
171
|
+
</script>
|
172
|
+
|
173
|
+
```
|
174
|
+
|
175
|
+
で送って、受け取り側は
|
176
|
+
|
177
|
+
```PHP
|
178
|
+
|
179
|
+
$name=filter_input(INPUT_POST,"name");
|
180
|
+
|
181
|
+
```
|
182
|
+
|
183
|
+
のような処理です。
|
2
追記
test
CHANGED
@@ -30,7 +30,7 @@
|
|
30
30
|
|
31
31
|
$('.submit button').on('click',function(e){
|
32
32
|
|
33
|
-
e.prevetDefault();
|
33
|
+
e.preventDefault();/**typo調整/
|
34
34
|
|
35
35
|
$.ajax({
|
36
36
|
|
@@ -57,3 +57,69 @@
|
|
57
57
|
```
|
58
58
|
|
59
59
|
※formDataは別途用意するものとする
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
# 追記
|
64
|
+
|
65
|
+
適当なフォームからデータをもらってform外のボタンをおしてajax送信
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
```javascript
|
70
|
+
|
71
|
+
$(function(){
|
72
|
+
|
73
|
+
$('.submit button').on('click',function(e){
|
74
|
+
|
75
|
+
e.preventDefault();
|
76
|
+
|
77
|
+
$.ajax({
|
78
|
+
|
79
|
+
url: '/sample/index',
|
80
|
+
|
81
|
+
type: 'GET',
|
82
|
+
|
83
|
+
data: {
|
84
|
+
|
85
|
+
hoge:encodeURIComponent($('#f1 [name=hoge]').val()),
|
86
|
+
|
87
|
+
fuga:encodeURIComponent($('#f1 [name=fuga]').val()),
|
88
|
+
|
89
|
+
},
|
90
|
+
|
91
|
+
dataType: 'text',
|
92
|
+
|
93
|
+
}).done(function(data){
|
94
|
+
|
95
|
+
console.log(data);
|
96
|
+
|
97
|
+
}).fail(function(xhr,err){
|
98
|
+
|
99
|
+
console.log(err);
|
100
|
+
|
101
|
+
});
|
102
|
+
|
103
|
+
});
|
104
|
+
|
105
|
+
});
|
106
|
+
|
107
|
+
</script>
|
108
|
+
|
109
|
+
```
|
110
|
+
|
111
|
+
```HTML
|
112
|
+
|
113
|
+
<form id="f1">
|
114
|
+
|
115
|
+
<input type="text" name="hoge" value="1">
|
116
|
+
|
117
|
+
<input type="text" name="fuga" value="漢字">
|
118
|
+
|
119
|
+
</form>
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
<div class="submit"><button type="button" name="mode" value="confirm"><img src="images/check.png" alt="送信"></button>
|
124
|
+
|
125
|
+
```
|
1
追記
test
CHANGED
@@ -7,3 +7,53 @@
|
|
7
7
|
- 別ウィンドに送信
|
8
8
|
|
9
9
|
(new window、target=_blank、frame、iframeなど)
|
10
|
+
|
11
|
+
|
12
|
+
|
13
|
+
# sample
|
14
|
+
|
15
|
+
sample追記します
|
16
|
+
|
17
|
+
|
18
|
+
|
19
|
+
```HTML
|
20
|
+
|
21
|
+
<div class="submit"><button type="button" name="mode" value="confirm"><img src="images/check.png" alt="送信"></button>
|
22
|
+
|
23
|
+
```
|
24
|
+
|
25
|
+
|
26
|
+
|
27
|
+
```javascript
|
28
|
+
|
29
|
+
$(function(){
|
30
|
+
|
31
|
+
$('.submit button').on('click',function(e){
|
32
|
+
|
33
|
+
e.prevetDefault();
|
34
|
+
|
35
|
+
$.ajax({
|
36
|
+
|
37
|
+
url: '/sample/index',
|
38
|
+
|
39
|
+
type: 'GET',
|
40
|
+
|
41
|
+
data: formData,
|
42
|
+
|
43
|
+
timeout: 10000,
|
44
|
+
|
45
|
+
dataType: 'text'
|
46
|
+
|
47
|
+
}).done(function(data){
|
48
|
+
|
49
|
+
console.log(data);
|
50
|
+
|
51
|
+
});
|
52
|
+
|
53
|
+
});
|
54
|
+
|
55
|
+
});
|
56
|
+
|
57
|
+
```
|
58
|
+
|
59
|
+
※formDataは別途用意するものとする
|