我正在尝试通过AJAX编辑我的购物车,一旦我点击编辑,它会检查STOCK
中的项目,如果库存在那里它更改了购物车并且我收到了消息,但是如果库存少了,我没有得到自定义消息,所以关键是,我只能得到成功和错误(内部服务器错误)消息,无法获取自定义消息少存货
jquery代码:
$.ajax({
type: "post",
url: "/devilmaycry/register?action=editcart",
data: {pid:pid,quant:quant,spid:spid,cartid:cartid},
success:
function()
{
if (xhr.responseText=="less stock")
alert("Stock is less");
else
alert("Item quantity has been changed in cart");
},
error:
function(xhr)
{
if(xhr.responseText=="Internal server error")
alert("item cannot be added , internal server error");
}
});
return false;
});
servlet代码:
else if(n.equals("editcart"))
{
int pid = Integer.parseInt(req.getParameter("pid"));
int spid = Integer.parseInt(req.getParameter("spid"));
int cartid = Integer.parseInt(req.getParameter("cartid"));
int quant = Integer.parseInt(req.getParameter("quant"));
k=o.editcart(cartid,pid,spid,quant);
if(k==2)
{
res.setStatus(HttpServletResponse.SC_ACCEPTED);
pw.write("less stock");
}
else if(k==0)
{
res.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
pw.write("Internal server error");
}
}
i haven't introduced the database logic because i have checked and it is working fine