Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/76.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
一个when中有多个jQuery延迟对象_Jquery_Promise_Jquery Deferred - Fatal编程技术网

一个when中有多个jQuery延迟对象

一个when中有多个jQuery延迟对象,jquery,promise,jquery-deferred,Jquery,Promise,Jquery Deferred,因此,如果我有多个Ajax调用,它们中的每一个是否都有可能进行回调并处于when-then状态???您必须将每个Ajax调用设置为延迟对象,然后将延迟对象设置为在.then方法中解析。是的,当然有可能。done方法甚至返回承诺,因此您可以简单地编写 $.when( $.ajax(…).done(function(r) { console.log("ajax 1 resolved with", r) }), $.ajax(…).done(function(r

因此,如果我有多个Ajax调用,它们中的每一个是否都有可能进行回调并处于when-then状态???

您必须将每个Ajax调用设置为延迟对象,然后将延迟对象设置为在.then方法中解析。

是的,当然有可能。done方法甚至返回承诺,因此您可以简单地编写

$.when(
    $.ajax(…).done(function(r) {
        console.log("ajax 1 resolved with", r)
    }),
    $.ajax(…).done(function(r) {
        console.log("ajax 2 resolved with", r)
    })
).done(function(r1s, r2s) {
    console.log("both ajax requests done");
});

我想你必须为每个对象创建一个单独的延迟对象。设置为延迟对象是什么意思?也许可以发布一个简短的代码示例。谢谢。承诺和延迟的目标需要一点时间才能让我的头脑清醒。你的回答帮了大忙