Created
October 24, 2019 20:53
-
-
Save akshay-nm/46e5cde28f0716b85c5593ad23c3be76 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', 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