質問編集履歴

2

不足

2016/09/16 00:58

投稿

zenexvs
zenexvs

スコア12

test CHANGED
File without changes
test CHANGED
File without changes

1

不足分の追記

2016/09/16 00:58

投稿

zenexvs
zenexvs

スコア12

test CHANGED
File without changes
test CHANGED
@@ -163,3 +163,201 @@
163
163
  どうかよろしくお願いします
164
164
 
165
165
  不足があったら申し付けてください。追記します
166
+
167
+
168
+
169
+ 追記(うまく<form>タグの内容をjsonにできていないみたいなので使っているコードを追記します。不足があったら申し付けてください。追記します)
170
+
171
+
172
+
173
+ HTML (セレクトボックスの内容はデータベースから拾ってます)
174
+
175
+ ```HTML
176
+
177
+
178
+
179
+ <f:form modelAttribute="DayLessonSearchFormMenu" action="${pageContext.request.contextPath}/day_lesson_search" class="form-inline" method="POST">
180
+
181
+ <div class="row">
182
+
183
+ <div class="form-group col-lg-2 col-md-2 col-xs-12">
184
+
185
+ <label>レッスン名</label>
186
+
187
+ </div>
188
+
189
+ <div class="form-group col-lg-2 col-md-2 col-xs-12">
190
+
191
+ <f:select path="LessonNameValue" items="${lessonNameList}"
192
+
193
+ itemLabel="LessonNameLabel" itemValue="LessonNameValue" class="form-control">
194
+
195
+ </f:select>
196
+
197
+ </div>
198
+
199
+ <div class="form-group col-lg-2 col-md-2 col-xs-12">
200
+
201
+ <label>教室名</label>
202
+
203
+ </div>
204
+
205
+ <div class="form-group col-lg-2 col-md-2 col-xs-12">
206
+
207
+ <f:select path="LessonRoomNameValue" items="${lessonRoomNameList}"
208
+
209
+ itemLabel="LessonRoomNameLabel" itemValue="LessonRoomNameValue" class="form-control">
210
+
211
+ </f:select>
212
+
213
+ </div>
214
+
215
+ <div class="form-group col-lg-2 col-md-4 col-sm-6 col-sm-12">
216
+
217
+ <label>担当講師名</label>
218
+
219
+ </div>
220
+
221
+ <div class="form-group col-lg-2 col-md-4 col-sm-6 col-sm-12">
222
+
223
+ <f:select path="InstructorNameValue" items="${instructorNameList}"
224
+
225
+ itemLabel="InstructorNameLabel" itemValue="InstructorNameValue" class="form-control">
226
+
227
+ </f:select>
228
+
229
+ </div>
230
+
231
+ </div>
232
+
233
+ <div class="row">
234
+
235
+ <div class="form-group col-lg-2 col-md-2 col-sm-3 col-xs-12">
236
+
237
+ <label>レッスン実施年</label>
238
+
239
+ </div>
240
+
241
+ <div class="form-group col-lg-2 col-md-2 col-sm-3 col-xs-12">
242
+
243
+ <f:select path="YearValue" items="${yearList}"
244
+
245
+ itemLabel="YearLabel" itemValue="YearValue" class="form-control">
246
+
247
+ </f:select>
248
+
249
+ </div>
250
+
251
+ <div class="form-group col-lg-2 col-md-2 col-sm-3 col-xs-12">
252
+
253
+ <label>レッスン実施月</label>
254
+
255
+ </div>
256
+
257
+ <div class="form-group col-lg-2 col-md-2 col-sm-3 col-xs-12">
258
+
259
+ <f:select path="MonthValue" items="${monthList}"
260
+
261
+ itemLabel="MonthLabel" itemValue="MonthValue" class="form-control">
262
+
263
+ </f:select>
264
+
265
+ </div>
266
+
267
+
268
+
269
+ </div>
270
+
271
+ <div class="row">
272
+
273
+ <div class="form-group col-lg-2 col-md-4 col-sm-6 col-sm-12">
274
+
275
+ <label>実施時間</label>
276
+
277
+ </div>
278
+
279
+ <div class="form-group col-lg-6 col-md-4 col-sm-6 col-sm-12">
280
+
281
+ <input type="text" class="form-control" placeholder="00:00">~
282
+
283
+ <input type="text" class="form-control"placeholder="23:59">
284
+
285
+ </div>
286
+
287
+ <div class="form-group col-lg-4 col-md-4 col-sm-6 col-sm-12">
288
+
289
+ <input type="submit" class="btn btn-default form-control
290
+
291
+ search_button" value="検索">
292
+
293
+ </div>
294
+
295
+ </div>
296
+
297
+ </f:form>
298
+
299
+
300
+
301
+ ```
302
+
303
+ 非同期通信と<form>の内容をjsonにして送るjavascriptです
304
+
305
+ ```javascript
306
+
307
+ $('[value=検索]').click(function() {
308
+
309
+ $('form').submit(function(event) {
310
+
311
+ event.preventDefault();
312
+
313
+ var lessonArr = $('form').serializeArray();
314
+
315
+ alert(JSON.stringify(lessonArr));
316
+
317
+ $('[value=検索]').attr('disabled', true);
318
+
319
+ $.ajax({
320
+
321
+
322
+
323
+
324
+
325
+ type : "GET",
326
+
327
+ url : "lesson_search", // リクエストURL
328
+
329
+ data : "lessonArr2=" + JSON.stringify(lessonArr),
330
+
331
+ datatype: "json",
332
+
333
+ success: function(data){
334
+
335
+ alert("ok");
336
+
337
+ console.log(data);
338
+
339
+ $('[value=検索]').attr('disabled', false);
340
+
341
+ location.reload();
342
+
343
+ },
344
+
345
+ error: function(data){
346
+
347
+ alert("値はコンソール参照");
348
+
349
+ $('[value=検索]').attr('disabled', false);
350
+
351
+ location.reload();
352
+
353
+ }
354
+
355
+
356
+
357
+ });
358
+
359
+ });
360
+
361
+ });
362
+
363
+ ```