views:

208

answers:

3

I am doing a cross domain request using $.ajax , it works on firefox and chrome but does not issue a call on IE 7,8. can anyone tell me whats wrong with the following??

  1. I have used JSON, JSONP, left that method due to some custom restrictions
  2. Usin Allow-access-control-origin headers already on my site(without that chrome and firefox was not making successful requests )
  3. Have already tried "https://developer.mozilla.org/en/http_access_control"

    $.ajax({
    type: 'GET',
    url: "http://anotherdomain.com/Service/GetControl?id=" + zoneID ,
    cache: false,
    contentType: "application/x-www-form-urlencoded" ,
    async: false,
    beforeSend: function (request) {
        //alert('before send');
        //request.setRequestHeader("X-Requested-With", "XMLHttpRequest");
        //request.setRequestHeader("X-PINGOTHER", "pingpong");
    
    
    } ,
    success: function (data, status) {
        //alert("Data returned :" + data);
        //alert("Status :" + status);
        if (status == "success" && data != "")
            $("#" + div.id).append(data);
        else
            $("#" + div.id).attr("style", "display:none;");
    },
    error: function (XMLHttpRequest, textStatus, errorThrown) {
        alert(textStatus);
        alert(errorThrown);
    }
    

    });

I am stuck with this code for last 2 days and have tried various tips present on multiple sites, but no luck yet. hope someone might have a working tip;).

A: 

It's hard to tell due to the lack of formatting in the question, but I think I see two issues with the ajax call.

1) the application/x-www-form-urlencoded for contentType should be in quotes

2) There should be a comma separating the contentType and async parameters.

KallDrexx
Hi Kall , thanks for your response. I tried your suggestion too , in question it was mistyped. Its working fine in Chrome and Firefox , for preflighted requests but not working in IE. Yet unable to tell why? please do share me any more tips if you have.
Furqan
A: 

Could you check if the problem with IE relies on not defining security zones to allow cross domain requests? See this microsoft page for an explanation.

OTOH, this page mentions that IE7 and eariler cannot do cross domain calls, but IE8 can, using a different object than XMLHttpRequest, the one JQuery uses. Could you check if XDomainRequest works?

Luciano
Thanks luciano, I Checked with XDomainRequest and for IE8 it worked, though i have to write seperate script to cater IE8 specially.
Furqan
what about this plugin http://plugins.jquery.com/files/jquery.cors.js.txt ?
Luciano
Furqan
A: 

Microsoft always ploughs a self-defeating (at least in IE) furrow:

http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/

CORS works with XDomainRequest in IE8. But IE 8 does not support Preflighted or Credentialed Requests while Firefox 3.5+, Safari 4+, and Chrome all support such requests.

Raman