2012-09-11 99 views
2

我想知道是否可以使用$().ready函數來測試是否有其他頁面已完全加載。jQuery函數檢查背景頁面是否完全加載?

在這裏我正在討論一個新聞源更新程序,該函數將發送一個POST請求到後臺php頁面以更新數據庫,然後使用ajax,新聞源將重新載入以獲取新數據。

function send_data(){ 
    var head = $("#headline").val(); 
    var news = $("#news").val(); 
    var info = '&headline='+head+'&news='+news; //update string 
    $.ajax({ 
     url: 'recieve_update.php', //updating php file 
     type: 'POST', 
     data: info     //data string 
    }); 

    $().ready(function() { 
     $("#newsfeed").load("load_news.php"); //reload the newsfeed viewer 
    }); 
} 

回答

1

使用的$.ajax()回調函數:

$.ajax({ 
    url: 'recieve_update.php', //updating php file 
    type: 'POST', 
    data: info,     //data string 
    success: function(){ 
     $("#newsfeed").load("load_news.php"); //reload the newsfeed viewer 
    } 
}); 
相關問題