bug^君 2019-07-21 09:11 采纳率: 25%
浏览 32

jQuery Promise内部的Promise [重复]

This question already has answers here:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/6538470/jquery-deferred-waiting-for-multiple-ajax-requests-to-finish" dir="ltr">jQuery Deferred - waiting for multiple AJAX requests to finish [duplicate]</a>
                            <span class="question-originals-answer-count">
                                (3 answers)
                            </span>
                    </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/5627284/pass-in-an-array-of-deferreds-to-when" dir="ltr">Pass in an array of Deferreds to $.when()</a>
                            <span class="question-originals-answer-count">
                                (9 answers)
                            </span>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2019-07-21 09:13:28Z" class="relativetime">9 months ago</span>.</div>
        </div>
    </aside>

I am creating array from ajax promise and after that I want to run my code. For that first loop each inside that loop ajax promise fetch record and add to the array and On first each loop promise I am running my code but each is promise is complete before array completed

my code

var attendeesId = []
 $('.tags-container > div[data-email]')
          .each(function() {
getCustomRequest(url).then(function(data) { //ajax promise function
              attendeesId.push(data.d.Id)
            })
})
.promise()
.done(function() {
console.log(attendeesId) //this runs before and shows empty
})

What I am doing wrong over here

</div>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥50 导入文件到网吧的电脑并且在重启之后不会被恢复
    • ¥15 (希望可以解决问题)ma和mb文件无法正常打开,打开后是空白,但是有正常内存占用,但可以在打开Maya应用程序后打开场景ma和mb格式。
    • ¥20 ML307A在使用AT命令连接EMQX平台的MQTT时被拒绝
    • ¥20 腾讯企业邮箱邮件可以恢复么
    • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
    • ¥15 错误 LNK2001 无法解析的外部符号
    • ¥50 安装pyaudiokits失败
    • ¥15 计组这些题应该咋做呀
    • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
    • ¥15 让node服务器有自动加载文件的功能