문제

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

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top