Getting IE to stop treating ajax as cross-domain,

2019-04-09 05:59发布

I have the following setup:

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

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


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


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.

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

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?

Thanks!

1条回答
神经病院院长
2楼-- · 2019-04-09 06:55

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;

This works for both GET and POST.

查看更多
登录 后发表回答