Last active
October 24, 2019 20:57
-
-
Save akshay-nm/a9b206fdc6832eee080eb4a91d198460 to your computer and use it in GitHub Desktop.
XHR request code
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
var httpRequest = new XMLHttpRequest() | |
httpRequest.open('GET', url, true) | |
httpRequest.timeout = 2000; | |
httpRequest.onload = function() { | |
console.log('Content value received from request:', JSON.stringify(JSON.parse(httpRequest.responseText).content)) | |
// purpose of adding a timeout here is just to mimic a limited bandwidth scenario... | |
setTimeout(() => { | |
document.querySelector('container-ce').content = JSON.stringify(JSON.parse(httpRequest.responseText).content) | |
}, 2000) | |
} | |
httpRequest.ontimeout = function() { | |
console.log('Request timed out') | |
} | |
httpRequest.send() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment