views:

263

answers:

3

I am trying to make an AJAX call from several domains to a single one which will handle the request. Enabling Cross domain in Firefox and Chrome was easy by setting the header on the handling server:

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

But this doesn't help enabling it in Internet Explorer. When I try:

httpreq.send('');

it stops with error Access denied.

How can this be enabled in Internet Explorer?

A: 

I don't believe you can do that directly in Internet Explorer. You have a couple of options:

  • Set up a proxy forwarding script on the server you do control that can forward the Ajax requests. Make sure that it only forwards to the appropriate destinations that you need so that you don't get turned into an anonymous relay.

  • Use the document.domain trick. Basically you need to create a set of iframes, one for each server you need to make Ajax calls to. Within each iframe set the document.domain property to exactly match the domain you need to send the Ajax requests to. As to how to populate the necessary data, use DOM manipulation prior to setting document.domain. Note that this trick requires the target servers to be in sub-domains of the original. More in this article, with examples.

Dan
Sorry for late response. I've done it with proxy script on server.
Aleksandar
A: 

For Internet Explorer 8, you need to do like for FF3, ie use the "Access-Control-Allow-Origin" header plus use XDomainRequest object instead of XMLHttpRequest. Everything is explaiend in detail here for IE8: http://msdn.microsoft.com/en-us/library/dd573303%28VS.85%29.aspx

Older flavours of IE don't support Cross Site Access Control nor XDomainRequest objects. However it's not over, you could resort to the IFrame trick for instance, ie creating an invisible IFrame that calls your functions as described here: htt://softwareas.com/cross-domain-communication-with-iframes

Eric
A: 

Just adding to the Eric's answer , for Older version of IE , you can use Jquery 1.4.2's $.ajax method , that by default allows the cross domain requests, or for cross domain JSON , you can use

jQuery.getJSON( String url, Map data, Function callback ) returns XMLHttpRequest

An Excerpt from Jquery docs.

"jQuery now supports JSONP natively - if you attempt to load JSON (via $.getJSON or $.ajax) from a remote URL then an extra callback will be provided for the server to interpret."

Furqan