Created
July 17, 2019 11:01
-
-
Save RolandWarburton/676655299eed9adb348f234b241f5bce to your computer and use it in GitHub Desktop.
xmlhttprequest simple setup
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
window.onload = function() { | |
console.log('loaded'); | |
const url = './file.txt'; | |
// make a new 'request'. | |
// request is an object so we use the keyword 'new' to make an instance of the XMLHttpRequest object | |
var request = new XMLHttpRequest(); | |
// GET data from a location | |
request.open('GET', url); | |
// prevent caching so when you reload it gets the data again | |
request.setRequestHeader('cache-control', 'no-cache, must-revalidate, post-check=0, pre-check=0'); | |
// what should happen when the data is loaded | |
request.onload = function() { | |
console.log(request); | |
document.querySelector('#test').innerHTML = request.response; | |
} | |
// it won't actually run until we tell it to | |
request.send(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment