!-- flowchart 箭头图标 勿删 --
get请求
function getJSON (url) {
return new Promise( (resolve, reject) => {
var xhr = new XMLHttpRequest();
xhr.open('GET', url, true);
xhr.onreadystatechange = function () {
// xhr 为 this
var resJson;
if (this.readyState === 4) {
if (this.status === 200) {
resolve(this.responseText, this);
} else {
resJson = { code: this.status, response: this.response };
reject(resJson, this);
}
}
}
xhr.send();
});
}
f