为什么以下XMLHttpRequest返回undefined?
function fetchFileList(){
var request = new XMLHttpRequest();
request.open("GET","../files.json",false);
request.onload = function(){
if(request.status == 200){
return request.responseText;
}
}
request.send();
}
,但是如果我是console.log()request.responseText
,控制台会输出它应该的内容:
if(request.status == 200){
console.log(request.responseText);
return request.responseText;
}
感谢。