Skip to content

Instantly share code, notes, and snippets.

@mdix
Created November 15, 2016 14:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mdix/740bc6a89b139c86865d801dc19cb1a8 to your computer and use it in GitHub Desktop.
Save mdix/740bc6a89b139c86865d801dc19cb1a8 to your computer and use it in GitHub Desktop.
XHR no connection wrapper
var req = new XMLHttpRequest();
req.open("post", 'https://jquery.com', true);
req.onreadystatechange = function receiveResponse() {
console.log('readyState: ', this.readyState);
console.log('status: ', this.status);
console.log('response: ', this.response.length);
if (this.readyState == 4) {
if (this.status === 0 && this.response.length === 0) {
return console.log('NO CON')
} else {
console.log("We go a response");
}
}
};
req.send();
req = null;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment