Skip to content

Instantly share code, notes, and snippets.

@foomin10
Created April 18, 2015 16:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save foomin10/57b8f20935fca0d34246 to your computer and use it in GitHub Desktop.
Save foomin10/57b8f20935fca0d34246 to your computer and use it in GitHub Desktop.
[Ajax] onreadystatechange の代わりに loadend イベントを使う ref: http://qiita.com/MizuiroFolder/items/99913016b1485fdf7c36
var xhr = new XMLHttpRequest();
xhr.onreadystatechange = function(){
if(xhr.readyState === 4 && xhr.status === 200){
console.log(xhr.response);
}
}
xhr.open('GET', '/path/to/file', true);
xhr.send();
var xhr = new XMLHttpRequest();
xhr.addEventListener('loadend', function(){
if(xhr.status === 200){
console.log(xhr.response);
}else{
console.error(xhr.status+' '+xhr.statusText);
}
});
xhr.open('GET', '/path/to/file', true);
xhr.send();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment