jquery如何使用多个Ajax调用一个在另一个之后结束 [英] jquery how to use multiple ajax calls one after the end of the other

查看:129
本文介绍了jquery如何使用多个Ajax调用一个在另一个之后结束的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 函数get_json()函数get_json() {
$(document).ready(function(){
$ .ajax({
url:'http://www.xxxxxxxxxxxxx',
data:{
name:'xxxxxx'
},
dataType:'jsonp',
// jsonp:'callback',
// jsonpCallback:'jsonpCallback',
成功:function(data){
$ .each(data.posts,function(i,post){
$ .mobile.notesdb.transaction(function(t){
t。 (',?,?,?,?,?,?,?,?,?,?,?,? ,?,?,?);',[post.Id,post.Code,post.Address,post.Name,post.Description,post.EntrySeason,post.Period,post.R即使是,post.PastPayments,post.todaypayments,post.paydate,post.receiptno],
// $.mobile.changePage('#page3','slide',false,true),
null );
});
$('#mycontent')。append(post.Name);
});
}
});

$ .ajax({
xxxx
});

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

如何强制第二个ajax调用在第一个结束后开始...第二个结束后的第三个,然后继续?

解决方案

将它们放在<$ c $

  $。ajax({
url:'http://www.xxxxxxxxxxxxx',
data:{name:'xxxxxx'},
dataType:'jsonp',
success:function(data){

//做东西

//调用下一个ajax函数
$ .ajax({xxx});
}
});


I am in mobile app and I use multiple Ajax calls to receive data from web server like below

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
        });
    });
}

How can I force the 2nd ajax call to begin after the end of the first... the 3rd after the end of the 2nd and so go on?

解决方案

Place them inside of the success: of the one it relies on.

$.ajax({
    url: 'http://www.xxxxxxxxxxxxx',
    data: {name: 'xxxxxx'},
    dataType: 'jsonp',
    success: function(data){

        // do stuff

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

这篇关于jquery如何使用多个Ajax调用一个在另一个之后结束的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆