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?

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

Your web method needs to be public and static.

Method 2

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

Method 3

Add public static before your method…

ex.

[WebMethod]
public static string MethodName() {}

Method 4

For ajax success:

For me, it was helpful to make:

  1. App_StartRouteConfig

    set
    from

settings.AutoRedirectMode = RedirectMode.Permanent;

to

settings.AutoRedirectMode = RedirectMode.Off;
  1. make your using method:
public

static
  1. add:
using System.Web.Services;

and on top of method using just:

[WebMethod] 

is enough

Method 5

First Of All Don’t Forget To Include
using System.Web.Services;

And Make Sure Your Method Should Be Public And Static and avoid adding Multiple Scripts in same Page like jquerymin.js shouldn’t be used for every Function/Method in same Page
[WebMethod]
public static sting MethodName(){}
I Had The Same Issue Which Using Ajax And Jquery To Check Username Exists
Or Not.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x