When I make a JQuery call, I get an Authentication failed response:
{
Message: "Authentication failed.",
StackTrace: null,
ExceptionType: "System.InvalidOperationException"
}
jQuery call:
$(document).ready(function () {
//Handle the change event for the drop down list
$("#ddRegions").change(function () {
//create the ajax request
$.ajax({
type: "POST", //HTTP method
url: '<%= ResolveUrl("WebForm2.aspx/getLocations")%>', //page/method name
data: "{}", //json to represent argument
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) { //handle the callback to handle response
//request was successful. so Retrieve the values in the response.
alert(msg.toSource());
}
});
});
});
The web method:
public static string getLocations() {
System.Diagnostics.Debug.WriteLine("Getting Locations.");
return "{region:auckland, city:auckland}";
}
I added the following to my web.config:
<authorization>
<allow users="*" />
</authorization>
<authentication mode="None" />
And I tried setting the AutoRedirectMode
to Off
in RouteConfig.cs
. This stops the error, but still the web method never gets called. Any suggestions?
dataType: 'json'
forces jquery to parse the response data automatically. But thegetLocations()
method returns invalid json. It should be:{"region":"auckland", "city":"auckland"}
. The double quotes are very important forJSON.parse()
. – Gravity