views:

42

answers:

2

Hello! I have 2 functions $.post jQuery, how to make the 2nd $.post carried out only after the loading of the first $.post completely finished? But I can not use $.post within $.post because the second $.post called from 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){});
    }
}

Sorry for bad english =)

+2  A: 

You could use the callback function of the first post:

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

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

marcgg
+2  A: 
$.post('/first/post/url', data1, function () {
    // this is executed once POST is sent
    $.post('/second/post/url', data2);
});
RaYell