Jquery – Call window.load function after AJAX has completed


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')): ?>
        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() {

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');
  url: ajaxurl,
  type: "POST",
  async: true,
  cache: true,
  data: {
    action: 'show_blog',
    term_id: term_id
  success: function(data) {   
      $('.blog-wrapper').fadeOut(1000, function() {

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($) {

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

Best Solution

Just trigger the onload event in the usual manner:

Related Question