ajax 前台页面不显示,后台也不报错
前台页面不显示,后台也不报错, No matching resource found - returning 404
Null ModelAndView returned to DispatcherServlet with name 'spring': assuming HandlerAdapter completed request handling
@RequestMapping(value="/Add")
@ResponseBody
public ReturnResult add(HttpServletRequest request, HttpServletResponse response) throws Exception {
String id = request.getParameter("entityId");
String quantityStr = request.getParameter("quantity");
Integer quantity = 1;
ReturnResult result=new ReturnResult();
System.out.println("员工id"+id);
if (!EmptyUtils.isEmpty(quantityStr))
quantity = Integer.parseInt(quantityStr);
//查询出商品
Product product = productService.getProductById(Integer.valueOf(id));
if(product.getStock()<quantity){
return result.returnFail("商品数量不足");
}
//获取购物车ss
ShoppingCart cart = getCartFromSession(request);
//往购物车放置商品
result=cart.addItem(product, quantity); //放入商品ID 和 商品数量
if(result.getStatus()==Constants.ReturnResult.SUCCESS){
cart.setSum((EmptyUtils.isEmpty(cart.getSum()) ? 0.0 : cart.getSum()) + (product.getPrice() * quantity * 1.0));
}
return result;
}
function addCartByParam(entityId,quantity){
//添加到购物车
$.ajax({
url: contextPath + "/Cart/Add",
method: "post",
data: {
entityId: entityId,
quantity: quantity
},
dataType="json",
success: function (result) {
var result = eval("(" + jsonStr + ")");
//状态判断
if (result.status == 1) {
showMessage("操作成功");
refreshCart();
}else{
showMessage(result.message);
}
},
error:function(result){
alert:("发生错误!");
}
} )
}