解决jq ajax 405,JQuery Ajax POST to Web API returning 405 Method Not Allowed

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?

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值