简体   繁体   English

让IE停止在iframe中将ajax视为跨域

[英]Getting IE to stop treating ajax as cross-domain, inside iframe

I have the following setup: 我有以下设置:

www.domain1.com/page1/ -- makes ajax POST request to www.domain1.com/page2/ www.domain1.com/page1/ - 向www.domain1.com/page2/发出ajax POST请求

www.domain1.com/page2/ -- returns json response www.domain1.com/page2/ - 返回json回复


www.domain2.com/page1/ -- embeds www.domain1.com/page1/ in iframe www.domain2.com/page1/ - 在iframe中嵌入www.domain1.com/page1/


When I load www.domain1.com/page1/ the ajax request is made and everything works. 当我加载www.domain1.com/page1/ ,会发出ajax请求并且一切正常。 When I load www.domain2.com/page1/ in Chrome or Firefox, www.domain1.com/page1/ is displayed in the iframe, and the ajax request is made fine. 当我在Chrome或Firefox中加载www.domain2.com/page1/时,iframe中会显示www.domain1.com/page1/ ,并且ajax请求正常。

When I try to load www.domain2.com/page1/ in IE7 / IE8, the ajax request gives a FORBIDDEN error -- it seems to be treating the request as cross-domain and blocking it, even though the request is being made from www.domain1.com/page1/ to www.domain1.com/page2/ . 当我尝试在IE7 / IE8中加载www.domain2.com/page1/时,ajax请求会出现FORBIDDEN错误 - 它似乎将请求视为跨域并阻止它,即使请求是从www.domain1.com/page1/www.domain1.com/page2/

It works fine in IE when the request is GET, but not POST. 当请求是GET时,它在IE中工作正常,但不是POST。 How can I get IE to stop treating this as cross-domain, just because the entire flow is contained in an iframe? 我怎样才能让IE停止将其视为跨域,只是因为整个流程都包含在iframe中?

Thanks! 谢谢!

jQuery v1.7.2 will fix CORS in IE, even if it isn't really CORS but IE thinks it is. jQuery v1.7.2将在IE中修复CORS,即使它不是真正的CORS但IE认为它是。
This simple boolean at the beginning of your JavaScript function should fix this behavior JavaScript函数开头的这个简单布尔值应该可以解决这个问题

$.support.cors = true;

This works for both GET and POST. 这适用于GET和POST。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM