Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET jQuery error: Unknown Web Method

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:

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?

like image 372
Mark Struzinski Avatar asked Oct 07 '08 19:10

Mark Struzinski


3 Answers

Your web method needs to be public and static.

like image 175
tvanfosson Avatar answered Nov 12 '22 18:11

tvanfosson


Clean the solution and rebuild. I've seen webmethods throw 500's until you do this.

like image 30
Cory House Avatar answered Nov 12 '22 17:11

Cory House


Add public static before your method...

ex.

[WebMethod]
public static string MethodName() {}  
like image 2
Tukaram Avatar answered Nov 12 '22 19:11

Tukaram