загрузка сообщений jQuery - PullRequest
       19

загрузка сообщений jQuery

1 голос
/ 15 февраля 2010

У меня есть 2 функции $ .post jQuery, как сделать, чтобы 2-й $ .post выполнялся только после полной загрузки первого $ .post? Но я не могу использовать $ .post внутри $ .post, потому что второй $ .post вызывается из flash

function play(id, file, dur, who, hname, artist, song)
{
    if($.cookie('scrobb') == 'on')
    {
        setTimeout(function(){
            $.post("/scrobbling/", { nowplaying: 1 , artist: artist, song: song, duration: dur},function(){});
        }, 5000);
    }
}

function songIsOver()
{
    if($.cookie('scrobb') == 'on')
    {
        $.post("/scrobbling/", { submission: 1 , artist: bartist, song: bsong, duration: bdur},
        function(data){});
    }
}

Извините за плохой английский =)

Ответы [ 2 ]

2 голосов
/ 15 февраля 2010
$.post('/first/post/url', data1, function () {
    // this is executed once POST is sent
    $.post('/second/post/url', data2);
});
2 голосов
/ 15 февраля 2010

Вы можете использовать функцию обратного вызова из первого сообщения:

$.post('ajax/first.html', function(data_first) {
  $.post('ajax/second.html', function(data_second) {
      $('.result').html(data_second);
  });
});

http://api.jquery.com/jQuery.post/

...