Home › Forums › Calendar Products › Events Calendar PRO › Run Custom Javascript after Ajax Call
- This topic has 5 replies, 2 voices, and was last updated 7 years, 8 months ago by
Glen Draeger.
-
AuthorPosts
-
July 12, 2018 at 1:57 pm #1574101
Glen Draeger
ParticipantI’m running some custom javascript on the photo feed. It works fine on initial page load. The issue I’m having is when the filter is used or you go to the “next page” of events the Javascript no longer works. I assume because the new content is being loaded via Ajax. Is there a hook I can use to run my custom javascript after the new content has been loaded? Can’t seem to find one.
July 12, 2018 at 2:09 pm #1574117Glen Draeger
ParticipantMaybe this is what I need?
tribe_is_ajax_view_request()
Will give it a shot.
July 12, 2018 at 3:17 pm #1574205Glen Draeger
ParticipantThis actually solved my issue. I’m leaving this ticket open in case there is something built into the calendar that might handle it more elegantly.
(function() { var origOpen = XMLHttpRequest.prototype.open; XMLHttpRequest.prototype.open = function() { console.log('request started!'); this.addEventListener('load', function() { console.log('request completed!'); console.log(this.readyState); //will always be 4 (ajax is completed successfully) console.log(this.responseText); //whatever the response was }); origOpen.apply(this, arguments); }; })();July 13, 2018 at 3:59 pm #1575109Cliff
MemberHi. Thanks for your detailed question.
It might be best to tie into photo-view-ajax-success.tribe from /wp-content/plugins/events-calendar-pro/src/resources/js/tribe-events-photo-view.js (or its minified version)
Additionally-helpful information might be available to you at https://theeventscalendar.com/support/forums/topic/revisited-public-filters-update-function/
Please let me know how this goes for you.
July 13, 2018 at 4:10 pm #1575117Glen Draeger
ParticipantPlease excuse my ignorance on this, but how exactly would I tie into that?
July 14, 2018 at 7:56 am #1575281Cliff
MemberLooking at the file I said it was located in (the non-minified version so it’s easy to read), you can have your JS wrapped with .on( ‘photo-view-ajax-success.tribe’ )
See http://api.jquery.com/on/ for additional reference and let me know if you have any follow-up questions on this topic.
August 5, 2018 at 9:35 am #1590631Support Droid
KeymasterHey there! This thread has been pretty quiet for the last three weeks, so we’re going to go ahead and close it to avoid confusion with other topics. If you’re still looking for help with this, please do open a new thread, reference this one and we’d be more than happy to continue the conversation over there.
Thanks so much!
The Events Calendar Support Team -
AuthorPosts
- The topic ‘Run Custom Javascript after Ajax Call’ is closed to new replies.
