My javascript to invoke the method in my c# class, the ajax call does get into success method but it does hit the c# method when I put in the break point. I tried changing the shoppingcart.aspx to shoppingcart.aspx.cs but still doesn’t hit the c# method.
<script type="text/javascript">
$('.removeCart').click(function (e) {
$.ajax({
type:"POST",
url: "ShoppingCart.aspx/deleteSelectedProduct/",
success: function () {
console.log("ITS GOING THROUH",e.target.dataset.removename);
},
error: function () {
}
});
});
</script>
my c# code
public void deleteSelectedProduct()
{
}
请您参考如下方法:
解决问题
- 您应该删除方法名称并将页面的 url 放入如下
url: "ShoppingCart.aspx",
并在 Page_load 事件上放置一个断点,如果它到达断点,这意味着您的 url 现在可以放置完整的 url 和方法名称。
url: "ShoppingCart.aspx/deleteSelectedProduct/",
现在您可以检查您的方法有什么问题,以下是可能的解决方案
- 你的方法
deleteSelectedProduct应该是静态方法 - 您需要在函数
deleteSelectedProduct上方添加[WebMethod]装饰
