0

been having trouble with this script, ive managed to get it working in ie8, works on chrome fine.

initilize: function(){
 $('#my_form').submit(function(){
  if ($.browser.msie && window.XDomainRequest) {     
   var data = $('#my_form').serialize();
   xdr=new XDomainRequest();
   function after_xhr_load()
   {
    response = $.parseJSON(xdr.responseText);
    if(response.number =="incorrect format"){
     $('#errors').html('error');
    }
    else
    {
     $('#errors').html('worked');
    }
   }
   xdr.onload = after_xhr_load;
   xdr.open("POST",$('#my_form').attr('action')+".json");
   xdr.send(data);

  } else {
   $.ajax({
    type: "POST",
    url: $('#my_form').attr('action')+".json",
    data: $('#my_form').serialize(),
    dataType: "json",
    complete: function(data) {
     if(data.statusText =="OK"){
      $('#errors').html('error');
     }
     if(data.statusText =="Created"){
      response = $.parseJSON(data.responseText);
      $('#errors').html('Here is your code:' +response.code);
     }
    }
  });
 }
 return false;
});
}

I understand that ie7 does not have the XDomainRequest() object. How can I replicate this in ie7.

Thanks, in advance

DickieBoy
  • 4,886
  • 1
  • 28
  • 47
  • Maybe your looking for JSONP, see http://stackoverflow.com/questions/3506208/jquery-ajax-cross-domain – sroes Oct 17 '12 at 16:37
  • Simple answer is you can't replicate it in IE7 without changing to a same-domain request or using JSONP rather than CORS. – Kevin B Oct 17 '12 at 17:32

1 Answers1

4

You are not going to get that code to work in IE7 since is cross domain calls are not supported in that old browser. You either need to change the backend to do a JSONP call or you need to use a serverside proxy.

epascarello
  • 204,599
  • 20
  • 195
  • 236