Javascript (405)同一域和服务器上的API和网站不允许使用方法

Javascript (405)同一域和服务器上的API和网站不允许使用方法,javascript,jquery,.net,api,Javascript,Jquery,.net,Api,我有一个网站,我正试图通过web API向数据库发出请求。API基本上更新一个位字段(在本例中是从0到1) 错误: $.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:

我有一个网站,我正试图通过web API向数据库发出请求。API基本上更新一个位字段(在本例中是从0到1)

错误:

$.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);
        }
 });
这都是从控制台

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应用程序,可以发布没有问题,但似乎网站有问题

问题:

$.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);
        }
 });

如何修复此405错误?这里发生了什么?

我认为这是一个api后端问题,您可能需要添加权限才能在api控制器中发布


查看CORS-这是您遇到的问题。可能重复的可能重复的不是那些处理跨域请求的链接。不过,我可以从iOS应用程序发布到Web API。