获取IE停止把AJAX跨域,里面的iframe里面、AJAX、IE、iframe

2023-09-11 22:30:07 作者:来自心底的你i

我有以下设置:

www.domain1.com/page1 / - 使得AJAX POST请求到 www.domain1.com/page2 /

www.domain1.com/page1/ -- makes ajax POST request to www.domain1.com/page2/

www.domain1.com/page2 / - 返回JSON响应

www.domain1.com/page2/ -- returns json response

www.domain2.com/page1 / - EMBEDS www.domain1.com/page1 / 在IFRAME

www.domain2.com/page1/ -- embeds www.domain1.com/page1/ in iframe

当我打开 www.domain1.com/page1 / 的AJAX请求,而且一切正常。当我打开 www.domain2.com/page1 / 在Chrome或Firefox, www.domain1.com/page1 / 显示在iframe和Ajax请求变细。

When I load www.domain1.com/page1/ the ajax request is made and everything works. 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.

当我尝试加载 www.domain2.com/page1 / 在IE7 / IE8,Ajax请求提供被禁止的错误 - 这似乎是治疗请求跨域和阻止它,即使请求正在从 www.domain1.com/page1 / www.domain1.com/第2页/

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/.

它工作正常,在IE浏览器时,该请求是GET,而不是职位。我怎样才能获得IE停止治疗这种跨域,只是因为整个流程被包含在一个iframe?

It works fine in IE when the request is GET, but not POST. How can I get IE to stop treating this as cross-domain, just because the entire flow is contained in an iframe?

谢谢!

推荐答案

jQuery的V1.7.2将修复在IE CORS,即使它是不是真的CORS但是IE认为它是。 在你的JavaScript函数开始这个简单的布尔应该解决这个问题。

jQuery v1.7.2 will fix CORS in IE, even if it isn't really CORS but IE thinks it is. This simple boolean at the beginning of your JavaScript function should fix this behavior

$.support.cors = true;

这适用于GET和POST。

This works for both GET and POST.