Reputation: 10066
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');
}
}
});
});
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);
});
}
});
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();
});
Then in my AJAX call I can also just call do_styling_function();
?
Upvotes: 1
Views: 7729
Reputation: 92893
Just trigger the onload
event in the usual manner:
jQuery(window).trigger('load');
Upvotes: 3