我想读取多个xml文件并将它们显示在HTML表格中。因此我写了以下代码:
var request1 = new XMLHttpRequest();
request1.open("GET", path_xml_1, true);
request1.onload = function(e) {
console.log("req1 joined!");
/*Read first xml here and display table!!!*/
console.log("req1 done!");
}
request1.send();
console.log("req1 send!");
var request2 = new XMLHttpRequest();
request2.open("GET", path_xml_2, true);
request2.onload = function(e) {
console.log("req2 joined!");
/*Read second xml here and display table!!!*/
console.log("req2 done!");
}
request2.send();
console.log("req2 send!");
以下内容已写入console.log:
req1 send!
req2 send!
req2 joined!
req2 done!
我不知道request1发生了什么。我只想执行request1.onload()中的所有代码,然后执行request2.onload()。任何想法必须改变什么?