Created
October 11, 2018 05:14
-
-
Save gaurav-gogia/27cad55891650b55a930e2ef4e586434 to your computer and use it in GitHub Desktop.
Trying to perform ajax/xhr via vanillajs. Am I doing this right? If not then please advise. Thanks :)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const XMLHttpRequest = require('xhr2'); | |
const xhr = new XMLHttpRequest(); | |
xhr.open('GET', 'http://twitter.com/DesmondANIMUS/'); | |
xhr.send(null); | |
xhr.onreadystatechange = function () { | |
var DONE = 4; // readyState 4 means the request is done. | |
var OK = 200; // status 200 is a successful return. | |
if (xhr.readyState === DONE) { | |
if (xhr.status === OK) | |
console.log(xhr.responseText); // 'This is the returned text.' | |
} else { | |
console.log('Error: ' + xhr.status); // An error occurred during the request. | |
} | |
console.log("Done"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment