2

I need to call a web method from Ajax call. See the below code which I'm using to make the Ajax call

$.ajax({
    type: "POST",
    url: '<%= ResolveUrl("WebForm1.aspx/CampaignData") %>',
    data: '{"CampName":' + params + '}',
    contentType: "application/json; charset=utf-8",
    dataType: "json",
    success: function (str) {
        // Handle success
        alert("Success call");
    },
    error: function (xhr, textStatus, errorThrown) {
        // Handle error
        alert("Fails");
    }

});

My web method is:

[WebMethod]
public static string CampaignData(string CampName)
{
    return CampName;
}
1
  • What config changes need to be done to use Ajax in .Net4.5 Commented Nov 30, 2016 at 7:52

1 Answer 1

2

I am using .Net 4.0 after change the flowing thing it started hitting the web method break point. Inside ~/App_Start/RouteConfig.cs change:

settings.AutoRedirectMode = RedirectMode.Permanent;

To:

settings.AutoRedirectMode = RedirectMode.Off;

(Or just comment the line)

Also if friendly URLs are enabled you need to change

url: "ConsultaPedidos.aspx/GetClients",

To:

url: '<%= ResolveUrl("ConsultaPedidos.aspx/GetClients") %>',

Hope this help somebody else

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.