【问题标题】:jQuery function to check if background page fully loaded?jQuery函数来检查背景页面是否已完全加载?
【发布时间】:2012-09-11 13:01:43
【问题描述】:

我想知道是否可以使用$().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
    }); 
}

【问题讨论】:

    标签: javascript jquery html ajax


    【解决方案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
         }
    }); 
    

    【讨论】:

      【解决方案2】:

      我相信只有这些线条才是您正在寻找的东西。直接来自 jQuery 源代码。 http://api.jquery.com/jQuery.ajax/

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

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-11-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-10-28
        相关资源
        最近更新 更多