Question

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

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top