Forums › Forums › Search & Filter Pro › Results don't show with AJAX, but do without AJAX
- This topic has 30 replies, 3 voices, and was last updated 8 years ago by Trevor.
-
Anonymous(Private) November 30, 2016 at 12:04 am #73010
Thanks for developing a wonderful plugin. I’m excited to get it working!
I’ve followed your instructions for displaying results with AJAX, as well as those with a custom theme, but am unable to get it to work. When the AJAX box is unchecked, it redirects me to a new page with perfect post results (Categories, Authors, Custom Taxonomy, Sort Order, etc). However, when using AJAX, while it does fade out the designated Results Container id, it doesn’t populate anything after it fades back in.
I’m using this on the homepage of the site, if that makes a difference, but I’ve also tried it on a basic page and as a sidebar widget on the Blog page.
I’ll be glad to grant any access necessary if you would like. Thank you for any help you can offer.
Anonymous(Private) November 30, 2016 at 12:08 am #73012I am using the NudieWP theme – http://nudiewp.com/ – if that helps.
Trevor(Private) November 30, 2016 at 8:38 am #73043Is the page using a javascript grid systems, such as Masonry or Isotope, to populate/re-populate the grid? If so, it needs to be re-initialized after our Ajax runs. Our FAQ page gives snippets to show how (sort of) and other users have posted on the forum how they did it too.
Anonymous(Private) November 30, 2016 at 5:25 pm #73303Ok, I’ve tried enqueuing the hooks listed in the FAQ within my functions file based on the instructions here: https://premium.wpmudev.org/blog/adding-jquery-scripts-wordpress/
No errors, JS initialized correctly, but it’s still not working.
The theme I’m using (NudieWP) is a very basic, no-frills blank bootstrap theme. Is there anything else I could try or information I could share that might help troubleshoot?
Anonymous(Private) November 30, 2016 at 5:36 pm #73313I’m not quite sure I understand what you need, but this is the code related to S&F that I have going:
On the page itself (within the WordPress editor):
[searchandfilter slug="sort-articles"] <hr/> <div id="dynamic-articles">
The enqueue action within my functions.php file:
add_action( 'wp_enqueue_scripts', 'child_theme_styles'); function theme_js() { wp_enqueue_script( 'theme_js', get_stylesheet_directory_uri() . '/js/sf-pro-ajax-events.js', array( 'jquery' ), '1.0', true ); } add_action('wp_enqueue_scripts', 'theme_js');
The archive template I’m using (which works when AJAX is disabled):
<?php /* * Template Name: Search & Filter * Description: Only to be used on homepage */ get_header(); // Loads the header.php template. ?> <div class="container"> <div id="content"> <?php get_template_part( 'loop' ); // Loads the loop.php template. ?> </div><!-- #content --> </div><!-- .container --> <?php get_footer(); // Loads the footer.php template. ?>
Anonymous(Private) November 30, 2016 at 6:24 pm #73323Oh, sorry. Here you go:
//depeding on where you add your JS, sometimes its necessary to wrap the above events in a function (as is standard practise): (function ( $ ) { "use strict"; $(document).on("sf:init", ".searchandfilter", function(){ console.log("S&F JS initialised"); }); //detects the start of an ajax request being made $(document).on("sf:ajaxstart", ".searchandfilter", function(){ console.log("ajax start"); }); //detects when the ajax request has finished and the content has been updated // - add scripts that apply to your results here $(document).on("sf:ajaxfinish", ".searchandfilter", function(){ console.log("ajax complete"); //so load your lightbox or JS scripts here again }); //an event fired when S&F is initialised and S&F scripts have been loaded $(document).on("sf:init", ".searchandfilter", function(){ console.log("S&F JS initialised"); }); }(jQuery));
-
AuthorPosts