jQuery函数检查后台页面是否满载?

时间:2012-09-11 13:01:43

标签: javascript jquery html ajax

我想知道是否可以使用$().ready函数来测试另一个页面是否已完全加载。

这里我说的是一个新闻源更新程序,其中该函数将向后台php页面发送POST请求以更新数据库,然后,使用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
    }); 
}

2 个答案:

答案 0 :(得分: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
     }
}); 

答案 1 :(得分:0)

我相信这些线条可能就是你想要的东西。直接来自jQuery源码。 http://api.jquery.com/jQuery.ajax/

$.ajax({
  url: "test.html",
  context: document.body
}).done(function() { 
  $(this).addClass("done");
});
相关问题