Run Custom Javascript after Ajax Call

Home Forums Calendar Products Events Calendar PRO Run Custom Javascript after Ajax Call

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #1574101
    Glen Draeger
    Participant

    I’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.

    #1574117
    Glen Draeger
    Participant

    Maybe this is what I need?

    tribe_is_ajax_view_request()

    Will give it a shot.

    #1574205
    Glen Draeger
    Participant

    This 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);
        };
    })();
    #1575109
    Cliff
    Member

    Hi. 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.

    #1575117
    Glen Draeger
    Participant

    Please excuse my ignorance on this, but how exactly would I tie into that?

    #1575281
    Cliff
    Member

    Looking 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.

    #1590631
    Support Droid
    Keymaster

    Hey 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

Viewing 7 posts - 1 through 7 (of 7 total)
  • The topic ‘Run Custom Javascript after Ajax Call’ is closed to new replies.