等待所有图像加载jquery ajax / jquery pjax

问题描述

| 这是我正在尝试做的事情的摘要
$.pjax = function( options ) {
  var $container = $(options.container),success = options.success || $.noop

  // We don\'t want to let anyone override our success handler.
  delete options.success

  // We can\'t persist $objects using the history API so we must use
  // a String selector. Bail if we got anything else.
  if ( typeof options.container !== \'string\' )
    throw \"pjax container must be a string selector!\"

  var defaults = {
    timeout: 650,push: true,replace: false,// We want the browser to maintain two separate internal caches: one for
    // pjax\'d partial page loads and one for normal page loads. Without
    // adding this secret parameter,some browsers will often confuse the two.
    data: { _pjax: true },type: \'GET\',dataType: \'html\',beforeSend: function(xhr){
      $container.trigger(\'start.pjax\')
      xhr.setRequestHeader(\'X-PJAX\',\'true\')
    },error: function(){
      window.location = options.url
    },complete: function(){


$container.trigger(\'end.pjax\')
},success: function(data){
  // If we got no data or an entire web page,go directly
  // to the page and let normal error handling happen.
  if ( !$.trim(data) || /<html/i.test(data) )
    return window.location = options.url

  // Make it happen.
  // i think im not getting it right.
  $(window).load(
      function() {
          $container.html(data)
      }
  );
就像要求jQuery在执行某些操作之前等待所有图像加载的官方方式,但在jquery ajax请求之后才执行。 正如您在底部的ѭ1处看到的那样,我试图在html(data)中的所有图像准备就绪后返回html(data),我们可以以某种方式做到这一点吗? 谢谢! 亚当·拉玛丹(Adam Ramadhan)     

解决方法

        我相信您必须在浏览器开始加载任何图像之前将加载的HTML插入DOM。您应该能够将其插入到隐藏的(
display:none
)div中,并在该隐藏的div上设置
.load()
回调。 此插件改进了
.load()
事件,以便在加载图像时更一致地触发它。     

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...