Reputation: 161
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;
}
Upvotes: 2
Views: 1030
Reputation: 161
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
Upvotes: 2