Created
October 31, 2017 06:24
-
-
Save vickonrails/da82d6118683dbb1e16d676f551def57 to your computer and use it in GitHub Desktop.
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 request = new XMLHttpRequest(); | |
request.addEventListener('progress',checkProgress);//fires when the readyState changes. | |
request.addEventListener('abort',abortMessage);// fires when the request is aborted. | |
request.addEventListener('error',errorMessage);// fires when an error occurs | |
request.addEventListener('load',handleRequest);// fires only when the request is successfull and data is sent back to the browser. | |
function handleRequest(){ | |
console.log(request.responseText); | |
} | |
function checkProgress(progress){ | |
var percentage = (progress.loaded / progress.total) * 100; | |
console.log(percentage); | |
} | |
function errorMessage(){ | |
console.log('sorry there was an error, please try again'); | |
} | |
function abortMessage(){ | |
console.log('sorry, this request was aborted'); | |
} | |
request.open('GET',url,true); | |
request.send(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment