js
1$(function(){ 2 $('#ajax').on('click',function(){ 3 4 $.ajax({ 5 url:'/home', 6 type:'GET', 7 data:{ 8 'fiscalYear':$('#fiscalYear').val(), 9 'yearMonth':$('#yearMonth').val(), 10 11 } 12 }) 13 .done( (searchResult) => { 14 console.log("hello"); 15 console.log("formList:" + searchResult); 16 17 $('result').html(searchResult); 18 console.log(searchResult); 19 for(var i=0; i < 'searchResult';i++){ 20 $('.result').append('<tr><td>' + testingDateFrom + '</td><td>' + testingDateTo + '</td><td>' + competitionName + '</td><td>' + Prefecture + '</td><td>' + Name + '</td><td>' + subName + '</td></tr>') 21 } 22 }) 23 .fail( (searchResult) => { 24 25 console.log("HTTPstatus : "+jqXHR.status); 26 27 }); 28 }); 29}); 30
data:{
'fiscalYear':$('#fiscalYear').val(),
'yearMonth':$('#yearMonth').val(),
} dataの値が取れたことをコンソール上で確認できました。
$resultに出力するテスト用のデータを作成し、正常に動くか確認をとりたいです。
controller
1@RequestMapping(value = "/home/search", method = RequestMethod.GET) 2 @ResponseBody 3 public String search(@ModelAttribute formList formList1,Model model ,@RequestParam Map<String, String> params) { 4 5 6 List<String> formList123 = Arrays.asList("dummy", 7 "dummy","dummy","dummy","preparing","UnSave"); 8 9 model.addAttribute("formList", formList1); 10 model.addAttribute("formList", formList123); 11 return "redirect:/home"; 12 } 13} 14
html
1<thead> 2 <tr> 3 <th>検査日</th> 4 <th>競技名</th> 5 <th>都道府県</th> 6 <th>団体名称</th> 7 </tr> 8 </thead> 9 <tbody th:text="$('#result')">> 10 <tr th:each="form:${formList}"> 11 <td th:text="${form.competitionDay}"</td> 12 <td th:text="${form.competitionName}"</td> 13 <td th:text="${form.competitionPlace}"</td> 14 <td th:text="${form.competitionNM}"</td> 15 </tr> 16 </tbody>
fiscalYear' と 'yearMonth'の検索条件により検査日、競技名、都道府県、団体名称の結果が返ってきます。その結果を以下のajaxの.append('文字列')に詰めたいです。
$('.result').append('<tr><td>' + testingDateFrom + '</td><td>' + testingDateTo + '</td><td>' + competitionName + '</td><td>' + Prefecture + '</td><td>' + Name + '</td><td>' + subName + '</td></tr>')
回答1件
あなたの回答
tips
プレビュー