Forums › Forums › Search & Filter Pro › Defining SF_LDATA after ajax page refresh?
- This topic has 4 replies, 2 voices, and was last updated 9 years, 8 months ago by Ross.
-
Anonymous(Private) March 2, 2015 at 3:31 pm #12672
I am using a custom script (djax.js) to perform Ajax page refreshing.
If I am navigating to the page with the filter on using the ajax refresh, I just get Uncaught ReferenceError: SF_LDATA is not defined error and the filter gets stuck.
I am using $getScript to load the plugin js after the page refresh so it appears on every page, but because my page is not hard reloading, the plugin never gets to define SF_LDATA unless I perform a hard reload on the page with the filter
Obviously, the filter works fine if you come into the site where the shortcode is (hard loading) but if I enter from the frontpage etc (ajax) the plugin just doesn’t work
Is there a way round this or a filter I can use to adapt the plugin so SF_LDATA can be defined when the page ajax refreshed with my script. It is really important or the whole flow of my dev will be broken.
As I am more of a code hack than a coder so any help would be very much appreciated.
Ross Moderator(Private) March 3, 2015 at 12:56 am #12705Hey Sarah
This is the problem I mentioned in my other message – there appears to be some JS errors on your site and its due to (possibly) your theme.
Essentially, to pass variables from PHP into JavaScript, WordPress provides a function – wp_localize_script. This, combined with the register_script should produce markup similar to the following:
<script type='text/javascript'> /* <![CDATA[ */ var SF_LDATA = {"ajax_url":"http:\/\/yoursite.com\/wp-admin\/admin-ajax.php","home_url":"http:\/\/yoursite.com\/","sfid":"0"}; /* ]]> */ </script> <script type='text/javascript' src='http://yoursite.com/wp-content/plugins/search-filter-pro/public/assets/js/search-filter-build.js?ver=1.4.0'></script>
So our JavaScript has an object (
SF_LDATA
) with a bunch of variables stored in which are required for the plugin to function.If you are not seeing output in your HTML, then again it seems like your theme/plugin is messing with WordPress standards and not allowing this plugin (and potentially others) to load their scripts properly.
I hope that makes sense!
Thanks
Anonymous(Private) March 4, 2015 at 12:49 pm #12816Further to my previous post adding
wp_enqueue_script( 'search-filter-plugin-build' );
to my child theme functions and then using $getScript in my ajax page loading script to reload the script after the page call seems to get it working.
So I’ve managed to poke around and fix it myself. 🙂
If anyone anticipates any problem doing it this way, I’d be grateful for any advice.
Ross Moderator(Private) March 6, 2015 at 2:34 am #12909Hey Sarah
Thanks for your persistence and updates! I’ll get back to your points shortly I’m just trying to get an update of S&F out of the door urgently! 🙂
Thanks
-
AuthorPosts