Senguttuvan Amaladass Senguttuvan Amaladass - 4 days ago 6
jQuery Question

Ajax call not working with web method

I need call a web method from Ajax call. find the below cade which I'm using
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;
}
need help to sort out this issue.

Answer

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

Comments