回答編集履歴
3
調整
test
CHANGED
@@ -214,7 +214,7 @@
|
|
214
214
|
|
215
215
|
$.ajax({
|
216
216
|
|
217
|
-
"url": '
|
217
|
+
"url": 'ajax.php',
|
218
218
|
|
219
219
|
"type": "POST",
|
220
220
|
|
2
さらに
test
CHANGED
@@ -181,3 +181,163 @@
|
|
181
181
|
?>
|
182
182
|
|
183
183
|
```
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
# さらに追記
|
188
|
+
|
189
|
+
|
190
|
+
|
191
|
+
何も選択されていなければ全て表示。
|
192
|
+
|
193
|
+
そこから選択されたものを以外を削っていくような形
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
- 元.htm
|
198
|
+
|
199
|
+
```HTML
|
200
|
+
|
201
|
+
<script>
|
202
|
+
|
203
|
+
$(function(){
|
204
|
+
|
205
|
+
$('.result').html('aaa');
|
206
|
+
|
207
|
+
$('button').on('click',function(event) {
|
208
|
+
|
209
|
+
event.preventDefault();
|
210
|
+
|
211
|
+
var html = '';
|
212
|
+
|
213
|
+
var formdata = new FormData($('#form').get(0));
|
214
|
+
|
215
|
+
$.ajax({
|
216
|
+
|
217
|
+
"url": 'y.php',
|
218
|
+
|
219
|
+
"type": "POST",
|
220
|
+
|
221
|
+
"dataType": "html",
|
222
|
+
|
223
|
+
"data":formdata,
|
224
|
+
|
225
|
+
"cache":false,
|
226
|
+
|
227
|
+
"processData": false,
|
228
|
+
|
229
|
+
"contentType": false,
|
230
|
+
|
231
|
+
}).done(function(data){
|
232
|
+
|
233
|
+
console.log(data);
|
234
|
+
|
235
|
+
$('.result').html(data);
|
236
|
+
|
237
|
+
});
|
238
|
+
|
239
|
+
});
|
240
|
+
|
241
|
+
});
|
242
|
+
|
243
|
+
</script>
|
244
|
+
|
245
|
+
<form id="form" name="search" action="" method="POST">
|
246
|
+
|
247
|
+
color:
|
248
|
+
|
249
|
+
<label><input type="radio" name="color" value="red">赤</label>
|
250
|
+
|
251
|
+
<label><input type="radio" name="color" value="blue">青</label><br>
|
252
|
+
|
253
|
+
type:
|
254
|
+
|
255
|
+
<label><input type="radio" name="type" value="a">a</label>
|
256
|
+
|
257
|
+
<label><input type="radio" name="type" value="b">b</label>
|
258
|
+
|
259
|
+
<label><input type="radio" name="type" value="c">c</label><br>
|
260
|
+
|
261
|
+
<button class="submit" value="検索">検索</button>
|
262
|
+
|
263
|
+
<input type="reset" value="リセット">
|
264
|
+
|
265
|
+
</form>
|
266
|
+
|
267
|
+
<section class="result"></section>
|
268
|
+
|
269
|
+
```
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
- ajax.php
|
274
|
+
|
275
|
+
少しパターンを増やしました
|
276
|
+
|
277
|
+
```PHP
|
278
|
+
|
279
|
+
$color=filter_input(INPUT_POST,"color");
|
280
|
+
|
281
|
+
$type=filter_input(INPUT_POST,"type");
|
282
|
+
|
283
|
+
$data = [
|
284
|
+
|
285
|
+
"test"=>[
|
286
|
+
|
287
|
+
[
|
288
|
+
|
289
|
+
"color"=>"red",
|
290
|
+
|
291
|
+
"type"=>"a",
|
292
|
+
|
293
|
+
],
|
294
|
+
|
295
|
+
[
|
296
|
+
|
297
|
+
"color"=>"red",
|
298
|
+
|
299
|
+
"type"=>"b",
|
300
|
+
|
301
|
+
],
|
302
|
+
|
303
|
+
[
|
304
|
+
|
305
|
+
"color"=>"blue",
|
306
|
+
|
307
|
+
"type"=>"a",
|
308
|
+
|
309
|
+
],
|
310
|
+
|
311
|
+
[
|
312
|
+
|
313
|
+
"color"=>"blue",
|
314
|
+
|
315
|
+
"type"=>"c",
|
316
|
+
|
317
|
+
],
|
318
|
+
|
319
|
+
[
|
320
|
+
|
321
|
+
"color"=>"yellow",
|
322
|
+
|
323
|
+
"type"=>"a",
|
324
|
+
|
325
|
+
],
|
326
|
+
|
327
|
+
],
|
328
|
+
|
329
|
+
];
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
$result = array_filter($data["test"],function($x) use($color,$type) {
|
334
|
+
|
335
|
+
return (is_null($color) or $x["color"]==$color) and (is_null($type) or $x["type"]==$type);
|
336
|
+
|
337
|
+
});
|
338
|
+
|
339
|
+
print_r($result);
|
340
|
+
|
341
|
+
```
|
342
|
+
|
343
|
+
$colorと$typeはand検索($colorも$typeも両方ヒットするもの)にしてあります
|
1
tuika
test
CHANGED
@@ -49,3 +49,135 @@
|
|
49
49
|
print_r($result);
|
50
50
|
|
51
51
|
```
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
# 追加分
|
56
|
+
|
57
|
+
- 元.htm
|
58
|
+
|
59
|
+
```javascript
|
60
|
+
|
61
|
+
<script>
|
62
|
+
|
63
|
+
$(function(){
|
64
|
+
|
65
|
+
$('.result').html('aaa');
|
66
|
+
|
67
|
+
$('button').on('click',function(event) {
|
68
|
+
|
69
|
+
event.preventDefault();
|
70
|
+
|
71
|
+
var html = '';
|
72
|
+
|
73
|
+
var formdata = new FormData($('#form').get(0));
|
74
|
+
|
75
|
+
$.ajax({
|
76
|
+
|
77
|
+
"url": 'ajax.php',
|
78
|
+
|
79
|
+
"type": "POST",
|
80
|
+
|
81
|
+
"dataType": "html",
|
82
|
+
|
83
|
+
"data":formdata,
|
84
|
+
|
85
|
+
"cache":false,
|
86
|
+
|
87
|
+
"processData": false,
|
88
|
+
|
89
|
+
"contentType": false,
|
90
|
+
|
91
|
+
}).done(function(data){
|
92
|
+
|
93
|
+
console.log(data);
|
94
|
+
|
95
|
+
$('.result').html(data);
|
96
|
+
|
97
|
+
});
|
98
|
+
|
99
|
+
});
|
100
|
+
|
101
|
+
});
|
102
|
+
|
103
|
+
</script>
|
104
|
+
|
105
|
+
<form id="form" name="search" action="" method="POST">
|
106
|
+
|
107
|
+
color:
|
108
|
+
|
109
|
+
<label><input type="radio" name="color" value="red" checked>赤</label>
|
110
|
+
|
111
|
+
<label><input type="radio" name="color" value="blue">青</label><br>
|
112
|
+
|
113
|
+
type:
|
114
|
+
|
115
|
+
<label><input type="radio" name="type" value="a" checked>a</label>
|
116
|
+
|
117
|
+
<label><input type="radio" name="type" value="b">b</label>
|
118
|
+
|
119
|
+
<label><input type="radio" name="type" value="c">c</label><br>
|
120
|
+
|
121
|
+
<button class="submit" value="検索">検索</button>
|
122
|
+
|
123
|
+
</form>
|
124
|
+
|
125
|
+
<section class="result"></section>
|
126
|
+
|
127
|
+
```
|
128
|
+
|
129
|
+
|
130
|
+
|
131
|
+
- ajax.php
|
132
|
+
|
133
|
+
```PHP
|
134
|
+
|
135
|
+
$color=filter_input(INPUT_POST,"color");
|
136
|
+
|
137
|
+
$type=filter_input(INPUT_POST,"type");
|
138
|
+
|
139
|
+
$data = [
|
140
|
+
|
141
|
+
"test"=>[
|
142
|
+
|
143
|
+
[
|
144
|
+
|
145
|
+
"color"=>"red",
|
146
|
+
|
147
|
+
"type"=>"a",
|
148
|
+
|
149
|
+
],
|
150
|
+
|
151
|
+
[
|
152
|
+
|
153
|
+
"color"=>"red",
|
154
|
+
|
155
|
+
"type"=>"b",
|
156
|
+
|
157
|
+
],
|
158
|
+
|
159
|
+
[
|
160
|
+
|
161
|
+
"color"=>"blue",
|
162
|
+
|
163
|
+
"type"=>"c",
|
164
|
+
|
165
|
+
],
|
166
|
+
|
167
|
+
],
|
168
|
+
|
169
|
+
];
|
170
|
+
|
171
|
+
|
172
|
+
|
173
|
+
$result = array_filter($data["test"],function($x) use($color,$type) {
|
174
|
+
|
175
|
+
return $x["color"]==$color and $x["type"]==$type;
|
176
|
+
|
177
|
+
});
|
178
|
+
|
179
|
+
print_r($result);
|
180
|
+
|
181
|
+
?>
|
182
|
+
|
183
|
+
```
|