2010-02-15 4 views
1

J'ai 2 fonctions $ .post jQuery, comment faire le 2ème $ .post effectué seulement après le chargement du premier $ .post complètement terminé? Mais je ne peux pas utiliser .post $ dans les .post de $ parce que le deuxième .post de $ appelé de la mémoire flashjQuery posts loading

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

Désolé pour le mauvais anglais =)

Répondre

2

Vous pouvez utiliser la fonction de rappel du premier message:

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

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

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