ASP.NET jQuery错误:未知的Web方法

Mar*_*ski 27 asp.net ajax jquery

这是我第一次尝试从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);
        }
    });
}
Run Code Online (Sandbox Code Playgroud)

这是我试图调用的页面方法:

[WebMethod()]
private static void CancelPlan(int activePlanId, string ntLogin)
{
    StrategyRetrievalPresenter presenter = new StrategyRetrievalPresenter();
    presenter.CancelExistingPlan(offer, ntLogin);            
}
Run Code Online (Sandbox Code Playgroud)

我通过使用和不使用parens'()来装饰Web方法来尝试这个.有人有想法吗?

tva*_*son 94

您的Web方法需要公开且静态.

  • 您的Web方法需要声明为"静态" (13认同)
  • 请注意,asmx中的Web方法不是这样,它们必须是公共的而不是静态的.请参阅http://stackoverflow.com/questions/4543347/webservice-unknown-web-method-parameter-name-methodname和http://stackoverflow.com/questions/3158678/unknown-web-method-exception-when-calling -shared-的WebMethod (9认同)
  • 如果当方法公开时我有这个错误怎么办? (3认同)
  • 好吧,那是一个愚蠢的错误。谢谢,不过..;) (2认同)

Cor*_*use 12

清理解决方案并重建.我见过webmethods抛出500's直到你这样做.