繁体   English   中英

jQuery加载文件在加载DOM时执行(不等待图像)

[英]Jquery load file to execute when DOM is loaded (not wait for images)

我目前正在使用

$('#message').load('/searchresult.php<? echo $requeststring; ?>', function() {
  $('#searching').hide();
});

要加载带有搜索结果的页面,但是它很慢,因为它在加载图像之前也不会显示。 加载DOM后,如何显示searchresult的内容?

在评论之后,我认为问题可能是您在.load()有一个回调函数,因此您可以尝试以下操作:

$('#message').load(function() { 
    $.ajax({
        type: "GET",
        url: '/searchresult.php<? echo $requeststring; ?>',
        success: function (result) {
             $('#searching').html(result);
        }
    });
});

PS jQuery API文档说, If a "complete" callback is provided, it is executed after post-processing and HTML insertion has been performed. The callback is fired once for each element in the jQuery collection, and this is set to each DOM element in turn. If a "complete" callback is provided, it is executed after post-processing and HTML insertion has been performed. The callback is fired once for each element in the jQuery collection, and this is set to each DOM element in turn. http://api.jquery.com/load/

PPS我的猜测是,由于一次处理每个功能的方式需要花费时间。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM