Created
April 18, 2015 16:33
-
-
Save foomin10/57b8f20935fca0d34246 to your computer and use it in GitHub Desktop.
[Ajax] onreadystatechange の代わりに loadend イベントを使う ref: http://qiita.com/MizuiroFolder/items/99913016b1485fdf7c36
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 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(); |
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 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