首页 > 嵌套ajax异步合并数据,不知如何实现

嵌套ajax异步合并数据,不知如何实现

    //获取列表
    $.ajax({
        url : 'http://...',
        method : get,
        dataType : 'json'
    }, function(ret, err) {

        //获取评论
        for(i in ret){
            $.ajax({
                url : 'http://...ret[i].id',
                method : get,
                dataType : 'json'
            }, function(ret2, err2) {
                //comment
                //这里不知道怎么写才能把列表和评论表组到一起输出,因为是异步,得到的comment总是空的。
            })
        }
        
    });

改为同步提交,锁住浏览器


参见: https://api.jquery.com/jquery.when/


原生的可以用 Promise.all()$.ajax 的话可以参考 sof 的这个链接:http://stackoverflow.com/questions/6538470/jquery-deferred-waiting-for-multiple-ajax-requests-to-finish

【热门文章】
【热门文章】