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

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

问题描述

我试图运行从本地主机这个剧本,但它得到一个错误的 405(不允许的方法)

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

我曾尝试与跨域:真正的 $ support.cors = ,但真正没有用,。任何想法?

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.

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

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

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

您也可以使用 jQuery.post() 包装方法做同样的事情。

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

请注意,在有关的特定网站还没有建立跨域的支持,因此,如果您需要访问,你需要得到该网站来解决这个问题,或者您需要使用您的服务器作为代理。

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

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