问题遇到的现象和发生背景
点击加入购物车不跳转
问题相关代码,请勿粘贴截图
<div class="goods_num">
<label>购买数量:</label>
<span><input type="text" value="1" id="good_nums" class="good_nums" /></span>
</div>
<div style="padding:20px 0;">
<span><a href="javascript:void(0)" id="cart_goods" class="goods_sub goods_sub_gou" >加入购物车</a></span>
</div>
<script>
$("#cart_goods").click(function () {
//1.获取productid,购买数量
var productId=${requestScope.Product.id};
var quantity=$("#good_nums").val();
//3.发送给服务器
$.post("${pageContext.servletContext.contextPath}/cart",{
productId:productId,
quantity:quantity,
action:"add"
},function (data) {
if (data==0){
window.location.href="${pageContext.servletContext.contextPath}/login";
}
else if (data==1){
window.location.href="${pageContext.servletContext.contextPath}/cart";
}
});
});
</script>
运行结果及报错内容
浏览器控制台报错
jquery.js:142
POST http://localhost:8080/mystore1_war_exploded/cart 405
ajax @ jquery.js:142
post @ jquery.js:135
(匿名) @ goods?productId=2:272
handle @ jquery.js:64
o @ jquery.js:57
我想要达到的结果
点击加入购物车后跳转购物车页面