我有一个网站,我试图通过Web API向数据库发出请求。 API基本上更新了一个位字段(在这种情况下从0到1)。
错误:
这一切都来自控制台。
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应用程序,可以POST没有问题,但似乎网站有问题。
问题:
如何修复此405错误?这里发生了什么?