这里我有一个javascript代码,它给了我错误的输出
var myids = "234,235,267";
var output = "";
var myTestValues = "";
var idsArray = myids.split(",");
var xhttp = new XMLHttpRequest();
for(var i=0; i<idsArray.length; i++) {
xhttp.open('GET', 'https://www.example.com/v1/buck?sessionId=123abc456&tid=1&eid=0&id='+idsArray[i]+'', true);
xhttp.timeout = 20000;
xhttp.onload = function () {
var status = xhttp.status;
if (status === 200) {
var data = JSON.parse(xhttp.responseText);
if (data.aExp.length > 0) {
myTestValues += data.aExp[0].id + "." + data.aExp[0].value + "|";
}
}
};
xhttp.ontimeout = function (e) {
alert('timeout');
};
}
xhttp.send();
output= myTestValues;
预期产量:234.1 | 235.0 | 267.3 |
输出我得到:267.3 | (最后一次迭代的值)
有人可以指出哪里出错了吗?