Skip to content

Instantly share code, notes, and snippets.

@avian2
Created July 24, 2017 11:11
Show Gist options
  • Save avian2/9393f9eae6be3cb7be44aae1e27eb4ba to your computer and use it in GitHub Desktop.
Save avian2/9393f9eae6be3cb7be44aae1e27eb4ba to your computer and use it in GitHub Desktop.
/* Why do this ... */
load: function(url) {
setTimeout(function () { doload(url) }, 1);
}
doload: function (url) {
/* synchronous XHR */
xhr.open("GET", url, false);
xhr.send(null);
/* do something with xhr.responseText ... */
}
/* ... instead of this? */
load: function(url) {
xhr.open("GET", url, true);
xhr.onreadystatechange = function() {
/* do something with xhr.responseText ... */
}
xhr.send(null);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment