request with XMLHttpRequest, 兼容性为: android 4.4以上, ios 8.0以上
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);
});
}