两个 Ajax 调用都是独立的,如果第一个调用延迟完成,那么第二个调用独立继续,您可以进行任意数量的 ajax 调用:10、20、30 ...
要更改方法,请使用以下功能
function asyncCall(url, method, varArray, functionCallBack)
{
var request, query;
query = '';
for (i in postArray)//format params
{
query += i + '=' + postArray[i] + '&';
}
try
{//for modern browsers
request = new XMLHttpRequest;
}
catch (err)
{// legacy IE
request = new ActiveXObject("Microsoft.XMLHTTP");
}
request.onreadystatechange = functionCallBack;
if(method == 'GET')
{
request.open("GET", url + '?' + query, true);
request.send();
}
else
{
request.open("POST", url, true);
request.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
request.send(query);
}
};
console.log('start 1');
asyncCall('url1', 'GET', {foo : 'bar'}, function(){console.log('Call 1');});
console.log('start 2');
asyncCall('url2', 'POST', {foo : 'bar'}, function(){console.log('Call 2');});
console.log('start 3');
asyncCall('url3', 'POST', {foo : 'bar'}, function(){console.log('Call 3');});