Re: [whatwg/xhr] Abandon hope of removing sync XHR from the web platform? (#20)

@I-Maps 
> a technique that requires javascript code to be loaded with synchronous XHR in the head of the document before the maps are initialized in the body onload event

I am curious, why don't you just initialize your maps in the xhr load callback (and wait that the document is ready) instead ?

You could do something like : 
```javascript

var loadPromise = new Promise(function(resolve) {
 window.addEventListener('load', resolve, true);
});


var req = new XMLHttpRequest();

req.onreadystatechange = function(event) {
 if (this.readyState === XMLHttpRequest.DONE) {
  if (this.status === 200) {
   var mydata = this.responseText;
   loadPromise.then(function() {
    initialize(mydata);
   });
  } else {
   console.log("Error: %d (%s)", this.status, this.statusText);
  }
 }
};

req.open('GET', 'http://myapi.com', true);
req.send(null);
```


-- 
You are receiving this because you are subscribed to this thread.
Reply to this email directly or view it on GitHub:
https://github.com/whatwg/xhr/issues/20#issuecomment-304698487

Received on Monday, 29 May 2017 16:40:48 UTC