Skip Navigation

[Resolved] Javascript not loading after Ajax sort

This support ticket is created 6 years, 3 months ago. There's a good chance that you are reading advice that it now obsolete.

This is the technical support forum for Toolset - a suite of plugins for developing WordPress sites without writing PHP.

Everyone can read this forum, but only Toolset clients can post in it. Toolset support works 6 days per week, 19 hours per day.

Sun Mon Tue Wed Thu Fri Sat
8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 8:00 – 12:00 - -
13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 13:00 – 17:00 - -

Supporter timezone: America/New_York (GMT-04:00)

This topic contains 1 reply, has 2 voices.

Last updated by Christian Cox 6 years, 3 months ago.

Assisted by: Christian Cox.

Author
Posts
#1153986

I'm using a very simple javascript (I plan to expand on it) that's attached to a 'view' for an archive list of custom Post Type that has taxonomies and categories that I wish to use for sorting.

I would like to use Ajax to update the sorting process, however I've discover that it won't refire after the Ajax update.

How can I get around it? Would it make a difference if it was written in JQuery. What about the 'frontend event handler'?

I've looked everywhere for an explanation & workaround.

You can see what I'm doing at -- hidden link

#1154056
Screen Shot 2018-11-27 at 2.07.11 PM.png

Hi, there is a button in the Search and Pagination JS panel that lets you hook into specific search and pagination events. See the attached screenshot. If you cannot see the Search and Pagination panel in the View editor screen, scroll to the top right corner and click "Screen Options". You can activate the Search and Pagination panel here. Then in the JS panel beneath it click "Frontend events" and choose "Custom Search" then "The custom search results have been updated". This will insert a jQuery event listener hook for you, and you can call some custom JavaScript function from within that hook. For example:

function myfunction( viewid ) {
  alert('View ' + viewid + ' has been updated');
}

jQuery( document ).on( 'js_event_wpv_parametric_search_results_updated', function( event, data ) {
	/**
	* data.view_unique_id (string) The View unique ID hash
	* data.layout (object) The jQuery object for the View layout wrapper
	*/
	myfunction( data.view_unique_id);
});

It's best to use the namespace jQuery instead of $ to access the jQuery object with Toolset.