Created
August 5, 2016 07:20
-
-
Save leohxj/4044244f41add9acf77fe938a4940eb2 to your computer and use it in GitHub Desktop.
request with XMLHttpRequest, 兼容性为: android 4.4以上, ios 8.0以上
This file contains hidden or 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
| function request(url, callback) { | |
| var xhr = new XMLHttpRequest(); | |
| xhr.open('GET', url, true); | |
| xhr.responseType = 'json'; | |
| xhr.onload = callback; | |
| xhr.send(); | |
| } | |
| // demo | |
| function getTopStories(callback) { | |
| request(HN_TOPSTORIES_URL, function(evt) { | |
| callback(evt.target.response); | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment