AJAX完成后调用window.load函数 [英] Call window.load function after AJAX has completed

查看:163
本文介绍了AJAX完成后调用window.load函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个wordpress主题,该主题具有许多样式选项等,可通过header.php文件读取该样式,并在此基础上进行样式和一些js的工作.例如,这是它的摘要:

I'm using a wordpress theme that has lots of styling options etc which is read by the header.php file and does styling and some js stuff based on that. For example, here is a snippet of what it looks like:

jQuery(window).load(function($) {
<?php if($data['blog_pagination_type'] == 'Infinite Scroll' || is_page_template('demo-gridblog.php')  || is_page_template('demo-timelineblog.php')): ?>
    jQuery('#posts-container').infinitescroll({
        navSelector  : "div.pagination",
                       // selector for the paged navigation (it will be hidden)
        nextSelector : "a.pagination-next",
                       // selector for the NEXT link (to page 2)
        itemSelector : "div.post",
                       // selector for all items you'll retrieve
        errorCallback: function() {
            jQuery('#posts-container').isotope('reLayout');
        }
    }
    });
});

这是一个片段,但还有更多.这是在我的header.php文件中.然后,我在custom.js文件中进行一些AJAX调用.看起来像这样:

This is a snippet but there is a lot more. This is in my header.php file. I then do some AJAX calls in my custom.js file. It looks something like this:

var term_id = $(this).attr('id');
$.ajax({
  url: ajaxurl,
  type: "POST",
  async: true,
  cache: true,
  data: {
    action: 'show_blog',
    term_id: term_id
  },
  success: function(data) {   
      jQuery(window).load();
      $('.blog-wrapper').fadeOut(1000, function() {
          $('.blog-wrapper').html(data);
          $(".blog-wrapper").fadeIn(1000);
      });
  }
});

我尝试使用jQuery(window).load();,但是我的header.php文件中的JS没有被触发.在AJAX调用之后,如何在我的header.php文件中重新触发window.load代码?我是否需要将其放在其他函数中,然后执行以下操作:

I tried to use jQuery(window).load(); but the JS from my header.php file doesn't get triggered. How can I re-trigger the window.load code in my header.php file after the AJAX call? Do I need to put it in a different function and then do something like this:

jQuery(window).load(function($) {
    do_styling_function();
});

然后在我的AJAX通话中,我也可以仅拨打do_styling_function();?

Then in my AJAX call I can also just call do_styling_function();?

推荐答案

只需以通常的方式触发onload事件:

Just trigger the onload event in the usual manner:

jQuery(window).trigger('load'); 

这篇关于AJAX完成后调用window.load函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆