更长的标题是:尝试使用Ajax调用到控制器上插入搜索结果到错误的表结果
“试图使用AJAX调用控制器插入搜索结果到一个表结果而留在同一个页面的结果为“405”或“直接自我参照导致循环......”错误”
我试图同时保持找到一种方法来填充搜索结果的表错误在同一页上使用ajax调用控制器。
ajaxCall->控制器 - >服务(完成搜索) - >控制器(来自搜索结果) - >回阿贾克斯与响应
我有被触发的形式提交防止违约后一个Ajax调用:
function ajaxGetSearchResults(link, form) {
var myList=[];
var jqxhr = $.ajax({
"url" : link,
"data" : form.serialize(),
"dataType" : 'json',
"type" : "POST",
"headers": {
'Content-Type': 'application/json'
},
"success" : function (response){
console.log("Ajax success");
fillTable(response);
console.log("Search results added to table: "+response);
},
"complete": function(response){
console.log("Ajax call to controller completed");
},
"error": function(){
console.log("Ajax call to controller triggered error");
}
});
}
在控制器我收到Ajax请求这样:
@RequestMapping(value = "/ajaxScriptSearch", method = RequestMethod.POST)
public @ResponseBody List<ResultViewDto> processAJAXRequestSearch(@RequestParam String a1,
@RequestParam String a2, @RequestParam String a3, @RequestParam String a4) {
SearchDto searchDto = new SearchDto();
searchDto.setAttribute1(a1);
searchDto.setAttribute2(a2);
searchDto.setAttribute3(a3);
searchDto.setAttribute4(a4);
try {
/*
calling Service, performing search using searchDto as a parameter, mapping result to resultViewDtos
*/
} catch(Exception e){
/* do something */
}
return resultViewDtos;
}
到服务的调用是全成。 resultViewDtos的一个例子是:[viewDto1,viewDto2,viewDto3]其中每个视图dto包含一些需要插入到表中的字符串值。
我似乎得到一个“HTTP状态405 - 请求方法'GET'不支持”的错误,但我的ajax调用是“type:POST”。
当我尝试使用GET insted时,我得到一个“直接自引用导致循环(通过引用链...)”的错误。
我使用杰克逊核心2.6.2,杰克逊数据绑定2.6.2,弹簧4,休眠4.
我会appericiate任何帮助我能......
添加整个弹簧控制器代码 –