Reputation: 322
In my spring project I am sending request through Ajax call like this:
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. So I just want to know that how can I access ajax call parameter in controller.
Upvotes: 0
Views: 1111
Reputation: 24442
Try setting the data as a JS object:
$.ajax({
type : "GET",
url : "http://localhost:8080/ preListOnSearch.do",
data : {currentPage: currentPage, appName: appName, appStatus: appStatus},
cache: false,
Upvotes: 1