gpt4 book ai didi

c# - 我看过通过 ajax 调用 c#,当我设置断点时,我的实现没有命中 c# 方法

转载 作者:太空宇宙 更新时间:2023-11-03 18:05:57 25 4
gpt4 key购买 nike

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()
{


}

最佳答案

解决问题

  1. 您应该删除方法名称并将页面的 url 放入如下

url: "ShoppingCart.aspx",

并在 Page_load 事件上放置一个断点,如果它到达断点,这意味着您的 url 现在可以放置完整的 url 和方法名称。

url: "ShoppingCart.aspx/deleteSelectedProduct/",

现在您可以检查您的方法有什么问题,以下是可能的解决方案

  1. 你的方法deleteSelectedProduct应该是静态方法
  2. 您需要在函数 deleteSelectedProduct 上方添加 [WebMethod] 装饰

关于c# - 我看过通过 ajax 调用 c#,当我设置断点时,我的实现没有命中 c# 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29764717/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com