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;
}
曾经蜡笔没有小新2017-05-17 10:08:19
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
巴扎黑2017-05-17 10:08:19
HttpServletResponse conflicts with the ajax callback, just remove HttpServletResponse.
迷茫2017-05-17 10:08:19
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.
淡淡烟草味2017-05-17 10:08:19
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) {
Long integral = impl.checkIntegral(Long.valueOf(carOwnerID));
PrintWriter writer=response.getWriter();
writer.write(String.valueOf(integral));
writer.flush();
writer.close();
}
怪我咯2017-05-17 10:08:19
The data type of your return value is json, but you returned a Map to him in the background. Convert your map to json