Ajax 405 (Method Not Allowed) Cross Domain Issue

五迷三道 提交于 2019-12-11 09:48:10

问题


I am trying to run this script from localhost but it gets an error 405 (Method Not Allowed) .

Code

$(document).ready(function(){

    $.ajax({
        url:'http://some.url/',
        type:'post',
        //crossDomain: true,
        data:'{id:"49"}',
        contentType: "application/json; charset=utf-8",
        dataType:'jsonp',

            success: function(responseData, textStatus, jqXHR) {
                alert('right');
                var value = responseData.someKey;
                console.log(value);
            },
            error:function() {
                alert("Sorry, I can't get the feed");  
            }
    });
});

I have tried with crossDomain:true and $.support.cors = true, but of no use.Any ideas?


回答1:


That has nothing to do with CORS, HTTP 405 means that your HTTP method is not permitted, e.g. GET, POST, etc.

According to Chrome dev tools, only POST and OPTIONS are permitted HTTP methods.

To send a POST request using jQuery.ajax(), use the following:

$.ajax('url', {
    // other settings here
    type: 'POST'
}

You can also use the jQuery.post() wrapper method to do the same thing.

Note that the particular site in question has not setup cross-origin support, therefore if you need to access this, you'll need to get the site to fix this issue or you'll need to use your server as a proxy.



来源:https://stackoverflow.com/questions/20065932/ajax-405-method-not-allowed-cross-domain-issue

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!