2010-11-11 85 views
0
我有困難打電話jQuery的AJAX調用後功能

完成加載jQuery的回調函數

function to_be_executed_last { 
    alert("The Call Is Complete"); 
    //some other stuff 
} 



$("a.jaxable_link").click(function(){ 
    $.post($(this).attr('href'), function(data) { 

     $('#container').html(data); 
//Execute the function to_be_executed_last here AFTER data has finished loading 
    }) 
}) 

我怎樣才能做到這一點? 感謝

回答

1

你只需要修復的簽名(失蹤括號),並調用它,就像這樣:

function to_be_executed_last() { 
    alert("The Call Is Complete"); 
    //some other stuff 
} 

$("a.jaxable_link").click(function(){ 
    $.post($(this).attr('href'), function(data) { 
    $('#container').html(data); 
    to_be_executed_last(); 
    }); 
}); 
+0

10秒。 10.秒。 ;-) *(在我之前,但你的是更完整的。)* – 2010-11-11 22:44:34

+0

這通常稱之爲呼叫完成之前的功能 – 2010-11-11 22:45:09

+0

@RisingSun:在呼叫完成之前它不會調用該功能,已經在上面)。他從「成功」回調中調用它,根據定義*在通話完成時發生。 – 2010-11-11 22:46:53

0

只需調用你的函數。收到響應時調用所有jQuery ajax函數的成功回調。