Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 859
bluepnume Avatar asked Nov 03 '22 20:11

bluepnume


1 Answers

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.

like image 174
John Bonfardeci Avatar answered Nov 09 '22 04:11

John Bonfardeci