ASP.NET jQuery 错误:未知的 Web 方法
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/179934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
ASP.NET jQuery error: Unknown Web Method
提问by Mark Struzinski
This is my first time attempting to call an ASP.NET page method from jQuery. I am getting a status 500 error with the responseText message that the web method cannot be found. Here is my jQuery $.ajax call:
这是我第一次尝试从 jQuery 调用 ASP.NET 页面方法。我收到一个状态 500 错误,带有无法找到 Web 方法的 responseText 消息。这是我的 jQuery $.ajax 调用:
function callCancelPlan(activePlanId, ntLogin) {
var paramList = '{"activePlanId":"' + activePlanId + '","ntLogin":"' + ntLogin + '"}';
$.ajax({
type: "POST",
url: "ArpWorkItem.aspx/CancelPlan",
data: paramList,
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function() {
alert("success");
},
error: function(xml,textStatus,errorThrown) {
alert(xml.status + "||" + xml.responseText);
}
});
}
And here is the page method I am trying to call:
这是我试图调用的页面方法:
[WebMethod()]
private static void CancelPlan(int activePlanId, string ntLogin)
{
StrategyRetrievalPresenter presenter = new StrategyRetrievalPresenter();
presenter.CancelExistingPlan(offer, ntLogin);
}
I have tried this by decorating the Web Method with and without the parens'()'. Anyone have an idea?
我已经通过使用和不使用括号'()'来装饰 Web 方法来尝试这个。有人有想法吗?
回答by tvanfosson
Your web method needs to be public and static.
您的网络方法需要是公共的和静态的。
回答by Cory House
Clean the solution and rebuild. I've seen webmethods throw 500's until you do this.
清洁溶液并重建。我已经看到 webmethods 抛出 500 直到你这样做。
回答by Tukaram
Add public static
before your method...
public static
在您的方法之前添加...
ex.
前任。
[WebMethod]
public static string MethodName() {}