Skip to content

Instantly share code, notes, and snippets.

@akshay-nm
Created October 24, 2019 20:53
Show Gist options
  • Save akshay-nm/46e5cde28f0716b85c5593ad23c3be76 to your computer and use it in GitHub Desktop.
Save akshay-nm/46e5cde28f0716b85c5593ad23c3be76 to your computer and use it in GitHub Desktop.
XHR request code
var httpRequest = new XMLHttpRequest()
httpRequest.open('GET', this.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