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;
}
7 回答

慕婉清6462132
TA貢獻1804條經驗 獲得超2個贊
請求成功有數據返回,很大可能與你的返回數據格式不對有關系。因為你設置了dataType : 'json' 預期服務器返回的數據類型
。這樣往往會進入 error
回調。你排除一下返回數據。
而且,error
是有三個回調參數的,請自行打印出來。

慕哥9229398
TA貢獻1877條經驗 獲得超6個贊
看到你的 dataType : 'json',
要求的是服務器返回json格式,
倘若服務器返回的數據不是json格式的數據,則會走進失敗的回調中。

慕尼黑5688855
TA貢獻1848條經驗 獲得超2個贊
將你AJAX配置dataType:"text",然后用alert(data)查看返回值
由于Ajax請求和response不一樣,得到數據后頁面不需要再渲染,所以不需要RESPONSE跳轉到新頁面。所以不需要RETURN,而是通過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();
}
添加回答
舉報
0/150
提交
取消