小编jok*_*edk的帖子

在循环中使用$ .Deferred()和嵌套的ajax调用

我花了太多时间寻找类似的问题和尝试解决方案,所以我希望有人有解决方案.

基本上,我希望在函数a()完成时得到通知.问题是该函数包含一个ajax调用和一个调用b()的循环,它再次包含一个ajax调用.

用FIDDLE更新:http://jsfiddle.net/hsyj7/1/

像这样:

// called by main()
function a() {
  return $.ajax("http://url1").pipe(function(data){
    for (var i = 0; i < 2; i++) {
      console.log('a called');
      b();
    }
  });
}

// called by a()
function b() {
  for (var i = 0; i < 2; i++) {
    $.ajax("http://url2", function(data){
      // do something
      console.log('b called');
    }
  }
}

function main(){
  $.when(a()).done(function(){
    console.log('all completed');
  });
}
Run Code Online (Sandbox Code Playgroud)

我希望看到的是,可能同时调用顶部的a():

a called
b called
b called
a called
b called
b called
all …
Run Code Online (Sandbox Code Playgroud)

javascript ajax jquery deferred

30
推荐指数
1
解决办法
1万
查看次数

webgrind在wamp上

我刚刚安装了wamp,最新版本附带了webgrind,但我无法弄清楚它是如何工作的.它说

Select a cachegrind file above
Run Code Online (Sandbox Code Playgroud)

就这样.

php profiling wamp xdebug

15
推荐指数
2
解决办法
2万
查看次数

标签 统计

ajax ×1

deferred ×1

javascript ×1

jquery ×1

php ×1

profiling ×1

wamp ×1

xdebug ×1