首先报的错误时:
前台:
function buy(id){
$.ajax({
type:'post',
url:'/demo/cart/buy',
data:{ "id": id },
contentType: "application/json; charset=utf-8",
dataType:'json',
success:function(data){
if(data.success){
$("#cartinfo_"+id).html("购买成功");
}else{
$("#cartinfo_"+id).html("购买失败");
}
},
error:function(){
}
});
后台
@RequestMapping(value = "/buy", method = {RequestMethod.POST,RequestMethod.GET})
@ResponseBody
public Map<String, String> addUser(@RequestBody Integer id,HttpServletRequest request,HttpServletResponse response) {
Map<String, String> map = new HashMap<String, String>(1);
try {
addToShoppingCart(id, request, response);
} catch (Exception e) {
map.put("success", "false");
}
map.put("success", "true");
return map;
}
求大神指点迷津呀呀呀。。