Frage

I'm performing a cross domain get request using similar to the code below (a very simplified version).

var addData = function() {
    $.ajax({
      type:'GET',
      url:'http://DifferentDomain.com/data.php',
      data:'body',
      success: function(data){
        $('body').html(data);
      }
    });
}

Now as IE doesn't support CORS I've needed to use an XDomainRequest using the iecors plugin which works great, as when IE fails with a XHttpRequest it then switches over to XDR.

However the issue I'm having is with $('body').html(data); This only seems to work in IE once I execute it live in the console, and not when it is first called on $(document).ready? (This works fine in all other browsers as they support XHR)

I think this is an issue with timing so I'm not really sure how to get around this, do I use a setTimeout() and run it twice for IE browsers?. Please can someone offer some advice? Many thanks in advance.

EDIT

I've found a workaround by executing it with a setTimeout , but still feel this isn't the best solution, e.g.

 setTimeout(function(){
   addData();
 },0);
War es hilfreich?

Lösung

I've found a workaround by executing it with a setTimeout , but still feel this isn't the best solution, e.g.

 setTimeout(function(){
   addData();
 },0);
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top