Ajax post HTML 405,Web API Ajax POST向返回 405方法不允许_jquery_开发99编程知识库
因此,我有一個像這樣的jquery ajax請求: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);
}
});
}
這是我的Web API,基本上是:[HttpPost]
public CreateCustomer.Response CreateCustomer(CreateCustomer.Request request)
{
HttpContext.Current.Response.AppendHeader("Access-Control-Allow-Origin","*");
. . .
當我在 Chrome 中調用它的時候,它給了我:OPTIONS http://myserver:111/Api/V1/Customers/CreateCustomer/405 (Method Not Allowed)
No 'Access-Control-Allow-Origin' header is present on the requested resource.
當我發出來自Fiddler的帖子請求時,它包含"access-control-allow-origin: 應答 header 中應該有 *",這將建議正確配置 API,但jquery請求的( 來自 Fiddler ) 如下所示:
那麼為什麼我的帖子請求變成了一個選項請求?
總結
以上是生活随笔為你收集整理的Ajax post HTML 405,Web API Ajax POST向返回 405方法不允许_jquery_开发99编程知识库的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: day4----函数-闭包-装饰器
- 下一篇: 营业收入的3个数据