Ajax 405(方法不允许)跨域问题 [英] Ajax 405 (Method Not Allowed) Cross Domain Issue

查看:7341
本文介绍了Ajax 405(方法不允许)跨域问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从localhost运行此脚本,但它收到错误 405(方法不允许)

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

代码

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

我尝试过 crossDomain:true $。support.cors = true ,但是没有用。任何想法?

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

推荐答案

与CORS无关,HTTP 405意味着您的HTTP方法不被允许,例如GET,POST等。

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

根据Chrome开发工具,只有POST和OPTIONS允许HTTP方法。

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

要发送使用 jQuery.ajax() ,使用以下命令:

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

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

您也可以使用 jQuery.post() wrapper方法

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

请注意,有问题的特定网站尚未设置跨原产地支持,因此,如果您需要访问此网站,则需要获取网站来解决此问题,否则您需要使用您的服务器作为代理。

这篇关于Ajax 405(方法不允许)跨域问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆