Skip to content

Instantly share code, notes, and snippets.

@akshay-nm
Last active October 24, 2019 20:57
Show Gist options
  • Save akshay-nm/a9b206fdc6832eee080eb4a91d198460 to your computer and use it in GitHub Desktop.
Save akshay-nm/a9b206fdc6832eee080eb4a91d198460 to your computer and use it in GitHub Desktop.
XHR request code
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