2010-02-15 95 views
1

我有2个函数$ .post jQuery,如何使第二个$ .post只在第一个$ .post加载完成后才进行? 但我不能.post的$中使用.post的$因为从闪存称为第二.post的$jQuery帖子加载

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

你可以使用第一篇文章的回调函数:

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