My Ajax call is not executing the web method and is returning status code "302 Found". Futher more... inspecting the trace shows that the method was actually sent as "OPTIONS"??
This was all working when the web method was in an aspx file. I had to move it to a asmx as I turned the code into a UserControl.
Ajax Call:
$.ajax({
type: "POST", //HTTP method
url: '<%= ResolveUrl("http://tempuri.org/PLService.asmx/getLocations")%>', //page/method name
data: "{}", //json to represent argument
contentType: "application/json; charset=utf-8",
dataType: "json",
success: processData //handle the callback to handle response
})
Web Method in PLService
[WebMethod]
public static string getLocations()
{
System.Diagnostics.Debug.WriteLine("Getting Locations.");
return "{\"region\":\"auckland\", \"city\":\"auckland\"}";
}
Request:
Host: tempuri.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Origin: http://localhost:1968 Access-Control-Request-Method: POST Access-Control-Request-Headers: cache-control,pragma Connection: keep-alive Pragma: no-cache Cache-Control: no-cache
Response Header:
Host: tempuri.org User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:37.0) Gecko/20100101 Firefox/37.0 Accept: text/html,application/xhtml+xml,application/xml;q=0.9,/;q=0.8 Accept-Language: en-US,en;q=0.5 Accept-Encoding: gzip, deflate Origin: http://localhost:1968 Access-Control-Request-Method: POST Access-Control-Request-Headers: content-type Connection: keep-alive Pragma: no-cache Cache-Control: no-cache