function a() {
$.ajax({
url : "http://localhost:8080/ubi/checkIntegral",
async : true,
data:{"carOwnerID":"111111"},
dataType : 'json',
type : 'GET',
success : function() {
alert("ss");
},
error : function(map){
alert("FALSE");
}
});
}
@RequestMapping(value="/checkIntegral",method = RequestMethod.GET)
@ResponseBody
public Map<String,Long> checkIntegral(@RequestParam String carOwnerID ,HttpServletRequest request,HttpServletResponse response){
Long integral = impl.checkIntegral(Long.valueOf(carOwnerID));
Map<String,Long> map = new HashMap<String, Long>();
map.put("msg", integral);
return map;
}
If the request is successful and data is returned, it may be related to the incorrect format of your returned data. Because you set the
dataType : 'json' 预期服务器返回的数据类型
。这样往往会进入error
callback. Please exclude the returned data.Moreover,
error
has three callback parameters, please print them out yourself.Some reasons why ajax jumps into error
Pop up your return value and see the data
HttpServletResponse conflicts with the ajax callback, just remove HttpServletResponse.
I see that your
dataType : 'json',
requires the server to return json format.If the data returned by the server is not in json format, it will go into a failed callback.
Configure your AJAX dataType: "text", and then use alert(data) to view the return value
Since Ajax requests are different from responses, the page does not need to be rendered after getting the data, so there is no need for RESPONSE to jump to a new page. So there is no need to RETURN, but print to the requested page through PrintWriter
@RequestMapping(value="/checkIntegral", method = RequestMethod.GET)
@ResponseBody
public void checkIntegral(@RequestParam String carOwnerID,HttpServletRequest request,HttpServletResponse response) {
}
I didn’t notice that this ajax is a cross-domain request.
The data type of your return value is json, but you returned a Map to him in the background. Convert your map to json