So I have a jquery ajax request like this:
function createLokiAccount(someurl) {
var d = {"Jurisdiction":17}
$.ajax({
type: "POST",
url:"http://myserver:111/Api/V1/Customers/CreateCustomer/",
data: JSON.stringify(d),
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data){alert(data);},
failure: function(errMsg) {
alert(errMsg);
}
});
}
This is hitting my web api which is basically:
[HttpPost]
public CreateCustomer.Response CreateCustomer(CreateCustomer.Request request)
{
HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin", "*");
...
Which when I call it in Chrome gives me:
OPTIONS http://myserver:111/Api/V1/Customers/CreateCustomer/ 405 (Method Not Allowed)
No 'Access-Control-Allow-Origin' header is present on the requested resource.
When I do the POST request from Fiddler it includes "Access-Control-Allow-Origin: *" in the response header as it should, which would suggest the API is configured correctly, yet the (from Fiddler) the jquery request looks like:
OPTIONS http://myserver:111/Api/V1/Customers/CreateCustomer/ HTTP/1.1
Host: myserver:111
Connection: keep-alive
Access-Control-Request-Method: POST
Origin: http://localhost:6500
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.116 Safari/537.36
Access-Control-Request-Headers: accept, content-type
Accept: /
Referer: http://localhost:6500/Home/Replication?interval=1
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8,en-GB;q=0.6,it-IT;q=0.4,it;q=0.2
So why is my POST request getting turned into an OPTIONS request?