2017-02-14 92 views
0

我有一個網站,我試圖通過Web API向數據庫發出請求。該API基本上更新一個位域(在這種情況下從0到1)。(405)方法不允許在同一域和服務器上的API和網站

錯誤:

這是所有從控制檯。

OPTIONS http://123.123.123.123:12345/project/webapi.svc/category/api/1/do/something 405 (Method Not Allowed) 

send @ jquery-1.12.4.js:10254 
ajax @ jquery-1.12.4.js:9738 
click @ PageModal.js:10 
(anonymous) @ jquery-ui.js:12443 
dispatch @ jquery-1.12.4.js:5226 
elemData.handle @ jquery-1.12.4.js:4878 

XMLHttpRequest cannot load http://123.123.123.123:12345/project/webapi.svc/category/api/1/do/something. Response to page.aspx preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://123.123.123.123' is therefore not allowed access. The response had HTTP status code 405. 

請求:

$.ajax({ 
    type: 'POST', 
    contentType: "application/json; charset=utf-8", 
    url: "http://123.123.123.123:12345/project/webapi.svc/category/api/1/do/something", //method Name 
    data: JSON.stringify({ id: ticketId }), 
    dataType: 'json', 
    error: function (msg) 
     { 
      alert("error: " + msg.status); 
     } 
}); 

我可以找到關於這是誰試圖從不同的域訪問API的人,但我是在同一個域的唯一的事。我也有一個iOS應用程序,可以在沒有問題的情況下發布,但看起來網站有問題。

問:

我怎樣才能解決這個405錯誤?這裏發生了什麼?

+0

直視CORS的API後端的問題 - 那就是你所遇到的問題。 –

+0

可能的重複http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource –

+0

可能重複[「No」Access-Control- Allow-Origin'標題出現在請求的資源「](http://stackoverflow.com/questions/20035101/no-access-control-allow-origin-header-is-present-on-the-requested-resource) –

回答