微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

jquery如何使用多个ajax调用一个结束后的另一个

我在移动应用程序,我使用多个ajax电话从网络服务器接收数据,如下所示
function get_json() {
    $(document).ready(function() {
        $.ajax({
            url: 'http://www.xxxxxxxxxxxxx',data: {
                name: 'xxxxxx'
            },dataType: 'jsonp',//jsonp: 'callback',//jsonpCallback: 'jsonpCallback',success: function(data) {
                $.each(data.posts,function(i,post) {
                    $.mobile.notesdb.transaction(function(t) {
                        t.executesql('INSERT into bill (barcode,buildingcode,buildingaddress,flatname,flatdescription,entryseason,period,amount,pastpayments,todaypayments,paydate,receiptno) VALUES (?,?,?);',[post.Id,post.Code,post.Address,post.Name,post.Description,post.EntrySeason,post.Period,post.Revenue,post.PastPayments,post.todaypayments,post.paydate,post.receiptno],//$.mobile.changePage('#page3','slide',false,true),null);
                    });
                    $('#mycontent').append(post.Name);
                });
            }
        });

        $.ajax({
            xxxx
        });

        $.ajax({
            xxxx
        });
    });
}

在第二次结束之后,如何强制第二次ajax调用开始之后…第三次,然后继续

thx提前为你的时间

解决方法

将它们放在成功之中:它所依赖的一个
$.ajax({
    url: 'http://www.xxxxxxxxxxxxx',data: {name: 'xxxxxx'},success: function(data){

        // do stuff

        // call next ajax function
        $.ajax({ xxx });
    }
});

原文地址:https://www.jb51.cc/jquery/182807.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐