[英]Receiving parameter in controller from Ajax call in Spring
In my spring project I am sending request through Ajax call like this: 在我的春季项目中,我通过Ajax调用发送请求,如下所示:
function doAjaxPost(currentPage) {
var appName = document.searchForm.txtZipFile.value;
var e = document.getElementById("selectStatus");
var appStatus = e.options[e.selectedIndex].text;
$.ajax({
type : "GET",
url : "http://localhost:8080/ preListOnSearch.do",
data : "currentPage=" + currentPage + "&appName=" + appName + "&appStatus="
+ appStatus,
cache: false,
success : function(response) {
alert(response);
},
error : function(e) {
alert('Error: ' + e);
}
});
}
And in my controller I wrote method like: 在我的控制器中,我编写了如下方法:
@RequestMapping(value = "/preListOnSearch", method=RequestMethod.GET)
public String preTestDataolx(@PathVariable("siteId") String siteId, @PathVariable(value = "currentPage") String currentPage,
@RequestParam(value = "appStatus") String appStatus) {
System.out.println(appStatus);
return "/preTestData";
}
But this give me error. 但这给我错误。 When I remove RequestParams from method definition it works fine.
当我从方法定义中删除RequestParams时,它工作正常。 So I just want to know that how can I access ajax call parameter in controller.
所以我只想知道如何访问控制器中的ajax调用参数。
Try setting the data as a JS object: 尝试将数据设置为JS对象:
$.ajax({
type : "GET",
url : "http://localhost:8080/ preListOnSearch.do",
data : {currentPage: currentPage, appName: appName, appStatus: appStatus},
cache: false,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.