我想在下面的getJsonData函数中返回xhr.responseText,该如何做?
function getJsonData(method, url){ var xhr = new XMLHttpRequest();
xhr.open(method, url, true);
xhr.onreadystatechange = function(){ if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200){ return xhr.responseText;
}
};
xhr.send();
}哈,已解决
function getAndDealJsonData(method, url, callback){ var xhr = new XMLHttpRequest();
xhr.open(method, url, true);
xhr.onreadystatechange = function(){ if(xhr.readyState == XMLHttpRequest.DONE && xhr.status == 200){ callback && callback(JSON.parse(xhr.responseText));
}
};
xhr.send();
}
跃然一笑
万千封印
随时随地看视频慕课网APP
相关分类