ie9 ajax请求跨域问题,使用IE9跨域AJAX请求(Cross-domain AJAX requests with IE9)

使用IE9跨域AJAX请求(Cross-domain AJAX requests with IE9)

除非请求dataType设置为“jsonp”或“script”,否则不会在IE9中执行跨域AJAX请求(使用jQuery 1.7.2制作)。

我在构建一个请求的时候发现了这个问题,在这个请求中我不关心响应,并且没有指定dataType(是的,我知道我应该关心响应)。

所以,例如,这将起作用:

$.ajax({

url: "http://www.google.com",

type: "GET", // or "POST"

dataType: 'jsonp'

});

但是这不会:

$.ajax({

url: "http://www.google.com",

type: "GET" // or "POST"

});

通过“工作”,我的意思是我看到在Firebug或F12中进行的HTTP请求。

这两个请求都适用于其他浏览器。 设置jQuery.support.cors = true; 不会影响成功,也不会将crossDomain设置为true,也不会将缓存设置为false(在AJAX请求中)。

为什么AJAX请求的成功取决于在IE中请求的数据类型? 我可以理解为什么它会影响我处理返回数据的能力; 我也明白,有些服务器可能会拒绝某个数据类型的所有请求(但这显然不是这种情况)。

Cross-domain AJAX requests (made using jQuery 1.7.2) are not performed in IE9 unless the request dataType is set to "jsonp" or "script".

I discovered this issue in framing a request where I did not care about the response and left dataType unspecified (yes, I know I should care about the response).

So, for example, this will work:

$.ajax({

url: "http://www.google.com",

type: "GET", // or "POST"

dataType: 'jsonp'

});

But this won't:

$.ajax({

url: "http://www.google.com",

type: "GET" // or "POST"

});

By "work" I mean that I see an HTTP request made in Firebug or F12.

Both requests work in other browsers. Setting jQuery.support.cors = true; does not affect success, nor does setting crossDomain to true nor cache to false (in the AJAX request).

Why should the success of an AJAX request depend on the dataType requested in just IE? I can understand why it would affect my ability to work with any returned data; I also understand that some servers might reject all requests for a certain dataType (but that is apparently not the case here).

原文:https://stackoverflow.com/questions/12058632

更新时间:2020-01-20 22:43

相关问答

如果启用CORS,则不需要使用JSONP。 Access-Control-Allow-Origin: http://www.example.com

如果在响应中设置了这个头部,那么普通的XmlHttpRequest就可以像访问相同的域一样访问响应。 检查这个标题设置是否正确。 我希望这个链接可以帮助你,如果你使用jQuery 一个CORS POST请求从普通的javascript工作,但为什么不用jQuery? 更新:示例 var xmlhttp= new XMLHttpRequest();

v

...

在您的javascript中,在调用$ .ajax(或等效的)强制跨域行为之前: JQuery.support.cors=true;

As you can see in my question's code I am prepending the proxy url in the JQuery.ajax function's beforeSend callback (proxy.beforeRequestSend). By the time this function is executed J

...

它不是为了阻止人们获取数据。 没有人得到它,你不能暴露。 它的设计使得: Alice,一个提供API的人,旨在通过Ajax进行访问 鲍勃,一个有网络浏览器的人 查理,第三方运行自己的网站 如果Bob访问查理的网站,那么查理无法将JS发送到Bob的浏览器,以便从Alice的网站获取数据并将其发送给Charlie。 如果Bob在Alice的网站上有一个用户帐户,允许他做一些事情,例如发表评论或删除数据,上述情况变得更加重要 - 由于没有保护,Charlie可以告诉Bob的浏览器在Bob的背后。 如果要

...

我能够通过使用xdomain库(在https://github.com/jpillora/xdomain上找到)来确定上述问题的解决方案,该库覆盖了请求行为以允许IE8和IE9中的跨域ajax。 这包括设置proxy.html,如xdomain站点上的示例所示,以及将Access-Control-Allow-Origin和其他相关标头添加到服务器响应。 这允许按照原始帖子中列出的条件在IE8 +中使用withCredentials进行跨域ajax JSON POST请求。 它还允许HTTP和HTT

...

由于GET和文本内容,我无法分别使用JSONP或XDR。 为此,我在我的页面中添加了一个iframe,其HTML位于客户端的服务器中。 因此,我们将数据发布到iframe,iframe然后将其发布到网络服务。 因此,消除了跨域引用。 我们添加了双向来源检查,以确认只有授权页面向iframe发送数据和从iframe发布数据。

并不是 header("Content-Control-Allow-Origin: *");

It should be header("Access-Control-Allow-Origin: *");

and not header("Content-Control-Allow-Origin: *");

你把 header('Access-Control-Allow-Origin: *');

在机器A上 如果您想要更安全,可以添加您的域名代替* - 例如http://www.foo.com header('Access-Control-Allow-Origin: http://www.foo.com');

You put header('Access-Control-Allow-Origin: *');

on machine A If you want to be more se

...

这是在Identity Server上未启用跨源资源共享(CORS)时的预期行为。 实际上,您可以为Identity Server启用CORS。 检查[1]如何操作。 [1] http://hasanthipurnima.blogspot.com/2016/05/applying-cors-filter-to-wso2-identity.html This is the expected behaviour when cross origin resource sharing (CORS) is

...

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值