Created
June 17, 2018 14:08
-
-
Save 0632347878/4014f1adf377c9c896baf5c7ed705b20 to your computer and use it in GitHub Desktop.
Custom get httpRequest
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 customGet ( url, cb ) { | |
var xmlhttp = new XMLHttpRequest(); | |
xmlhttp.onreadystatechange = function() { | |
if (this.readyState == 4 && this.status == 200) { | |
var data = JSON.parse(xmlhttp.response); | |
cb(data); | |
} | |
}; | |
xmlhttp.open("GET", url, true); | |
xmlhttp.send(); | |
} | |
customGet('./ajax_info.json', function ( response ) { | |
var all = 0; | |
for (var key = 0; key < response.length; key++) { | |
console.log('key', key, '\ndata', response[key]); | |
all += response[key].age; | |
} | |
}); |
Author
0632347878
commented
Aug 13, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment