Javascript 多个settimeout调用的时间段计数

Javascript 多个settimeout调用的时间段计数,javascript,jquery,Javascript,Jquery,在几个ajax请求期间,依赖函数在特定时间段被调用。我的问题是,有没有办法在不使用settimeout函数中的事件的情况下找到总时间周期200+300+500 //main ajax calls using following functions setTimeout(function(){ avg(10,15,30); alert('I am triggered at 2ms');//dependant function 1 (calculate avg) },200); se

在几个ajax请求期间,依赖函数在特定时间段被调用。我的问题是,有没有办法在不使用settimeout函数中的事件的情况下找到总时间周期200+300+500

//main ajax calls using following functions
setTimeout(function(){
    avg(10,15,30);
    alert('I am triggered at 2ms');//dependant function 1 (calculate avg)
},200);
setTimeout(function(){
    total(50,100,30);
    alert('I am triggered at 3ms');//df 2(calculate total)
},300);
setTimeout(function(){
    vat_cal(180,12.5);
    alert('I am triggered at 5ms');//df 3(calculate vat % for total)
},500);
假设我不知道setTimeout被使用了多少次。 因此,如果已知时间因素,则更容易加载带有通知的数据


多个ajax请求正在消耗数据加载时间。如果我知道总时间200+300+500=1000。我可以通知用户等待一秒钟。

您的问题似乎有点模糊。但如果您想重复setTimeout函数几次,最好使用setInterval函数。
我真的没有得到你想要的结果,但它应该有用。

我不知道你想描述什么。你能举一个更具体的例子说明你想做什么吗?你能详细说明你的问题吗。。
[Code is Here][1]


  [1]: http://jsfiddle.net/asomani/2y0t60g5/2/

Use When and Then callback method and in the last ajax request complete call the time Calculate Method.

window.time1 = new Date().getTime();

function aCallback()
{
   window.time2 = new Date().getTime(); 
   total_time = (window.time2 - window.time1)

}

$.when($.ajax({
    data: {test:"1"}
}), $.ajax({
    data: {test:"1"}
}),$.ajax({
    data: {test:"1"},
  success: aCallback
}) ).done(function( x,y,z ) {
    alert(total_time ); 

});
function avg(x1,x2,x3)
{
 alert(x1+x2+x3)

}

function total(x1,x2,x3)
{
 alert(x1+x2+x3)

}

function vat_cal(x1,x2,x3)
{
 alert(x1+x2+x3)

}


$.when(  avg(10,15,30),total(50,100,30), vat_cal(180,12.5) ).done(function( x,y,z ) {
   alert("finish")  
});