调用多个Ajax调用多个、Ajax

由网友(冷风吹i)分享简介:$.ajax({url: "",jsonpCallback: 'item',contentType: "application/json",dataType: 'jsonp',success: function(data) {console.log(data);var markup = "";$.each(data....
 $.ajax({
        url: "",
        jsonpCallback: 'item',
        contentType: "application/json",
        dataType: 'jsonp',

        success: function(data) {
            console.log(data);
            var markup = "";
            $.each(data.list, function(i, elem) {
                dbInsert(elem['itemCode'], elem['description'], elem['price']);
            });

        },
        error: function(request, error) {
            alert(error);
        }
    });

我有不同的URL不同Ajax调用上述类型。我怎样才能运行每个Ajax调用,一个又一个?

I have the above type of different ajax calls with different urls. How can I run each Ajax call, one after another?

推荐答案

您可以做这样的事情。

$('#button').click(function() {
    $.when(
        $.ajax({
            url: '/echo/html/',
            success: function(data) {
                alert('one is done')
            }
        }),
        $.ajax({
            url: '/echo/html/',
            success: function(data) {
                alert('two is done')
            }
        })
    ).then( function(){
        alert('Final Done');
    });
});

小提琴

阅读全文

相关推荐

最新文章