Cross domain ajax POST ie7 with jquery

Posted by DickieBoy on Stack Overflow See other posts from Stack Overflow or by DickieBoy
Published on 2012-10-17T16:33:51Z Indexed on 2012/10/17 17:01 UTC
Read the original article Hit count: 228

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

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about jQuery