我试图从jquery调用asp.net webmethod.But它永远不会从Jquery调用.
[WebMethod]
public void AddProductToCart(int productid)
{
Response.Write(productid.ToString());
MyShoppingCart usersShoppingCart = new MyShoppingCart();
String cartId = usersShoppingCart.GetShoppingCartId();
try
{
usersShoppingCart.AddItem(cartId, productid, 1);
}
catch (Exception ex)
{
throw new Exception(ex.Message);
}
Run Code Online (Sandbox Code Playgroud)
Jquery函数
function d(t) {
e.ajax({
url: "productmodel.aspx/AddProductToCart",
type: "POST",
data: JSON.stringify(t),
dataType: "json",
contentType: "application/json; charset=utf-8",
sucess: function () {
alert("added to cart successfully");
}
})
}
Run Code Online (Sandbox Code Playgroud)
请帮我解决这个问题.