Skip to:

Opened 9 years ago

Closed 6 years ago

#6302 closed enhancement (maybelater)

Add callbacks/events when ajax functions have finished

Reported by: bowromir's profile Bowromir Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Core Keywords: needs-patch, trac-tidy-2018
Cc: roger@…, brajesh@…


It would be handy to provide a callback when AJAX actions have finished. This would allow developers to easily (re)load javascript functions in places like the activity stream and component directories.

Change History (21)

#1 @swissspidy
9 years ago

  • Cc hello@… added

This ticket was mentioned in Slack in #buddypress by modemlooper. View the logs.

9 years ago

#3 @modemlooper
9 years ago

i'll submit a patch needed triggers more than once.

#4 @rogercoathup
9 years ago

Note -- jQuery provides a generic ajaxStop event handler that you can use:

This works well in conjunction with the activity stream.

#5 @rogercoathup
9 years ago

  • Cc roger@… added

#6 @sbrajesh
9 years ago

As rogercoathup suggested, It can be accomplished via javascript.
I have been using ajaxComplete to register the handler and It works great fro the activity. You can evn sniff action etc

#7 @sbrajesh
9 years ago

  • Cc brajesh@… added

#8 @modemlooper
9 years ago

tried that and it didn't work or I should say it keeps running during any ajax. Post code or your you lie ;P

Last edited 9 years ago by modemlooper (previous) (diff)

#9 @sbrajesh
9 years ago

Hi modemlooper,
Here is the code example

   jQuery( document ).ajaxComplete( function( evt, xhr, options ) {
       var action = get_var_in_query( 'action', ) ;
       switch( action ){
           case 'post_update':
               console.log('Activity was posted');

   function get_var_in_query( item,  str ){
       var items;
       if( !str )
           return false;
       var data_fields = str.split('&');
       for( var i=0; i< data_fields.length; i++ ){
           items = data_fields[i].split('=');
           if( items[0] == item )
               return items[1];
       return false;

I am using a helper function 'get_var_in_query' to find an item in the query string.

The above example should log into the console when the the activity is posted and a response is returned.

#10 @modemlooper
9 years ago

oh, Bowe needs triggers for activity/groups/members filters

#11 @sbrajesh
9 years ago

In that case, we can add the following cases to the switch case(These are the ajax actions)

  1. activity_widget_filter for activity filter
  2. groups_filter
  3. members_filter

Also, It can be further customized by checking for 'filter' value to see which drop down item was selected.
Hope that helps :)

#12 @modemlooper
9 years ago

yup, weird its working now. Had tried the exact thing earlier. doing this could be an issue if you placed and ajax method inside.

Last edited 9 years ago by modemlooper (previous) (diff)

#13 @DJPaul
9 years ago

  • Keywords reporter-feedback added
  • Milestone changed from Awaiting Review to Under Consideration

@Bowromir could you provide a basic example of the sort of change you'd like to see made to the core scripts? If it's a trivial non-breaking change, we could consider it for BP-Legacy, otherwise it will likely wait until we build a new template pack later this year (with brand new, non-crappy JS).

#14 @rogercoathup
9 years ago

@DJPaul -- when the rewrite of the JS is done, I guess you'll be using Backbone. In that case, liberal use of trigger callbacks would seem the best solution. Firing the triggers when filters etc. start / finish their work -- allowing 3rd party JS to hook in.

#15 @swissspidy
9 years ago

  • Cc hello@… removed

#16 @modemlooper
9 years ago


jq(document).trigger('bp_activity_request', [ scope, filter ] );

to response function of bp_ajax_request = ajaxurl, {

#17 @DJPaul
9 years ago

  • Keywords needs-patch added; reporter-feedback removed
  • Milestone changed from Under Consideration to Future Release

Happy to have a look at a patch if someone wants to propose something minimal and non-invasive.

#18 @rogercoathup
9 years ago

Note: this project might provide useful foundation -- supports actions and filters on WP / JS

#19 @DJPaul
8 years ago

  • Component changed from Component - Any/All to Core

#20 @DJPaul
6 years ago

  • Keywords trac-tidy-2018 added

We're closing this ticket because it has not received any contribution or comments for at least two years. We have decided that it is better to close tickets that are good ideas, which have not gotten (or are unlikely to get) contributions, rather than keep things open indefinitely. This will help us share a more realistic roadmap for BuddyPress with you.

Everyone very much appreciates the time and effort that you spent sharing your idea with us. On behalf of the entire BuddyPress team, thank you.

If you feel strongly that this enhancement should still be added to BuddyPress, and you are able to contribute effort towards it, we encourage you to re-open the ticket, or start a discussion about it in our Slack channel. Please consider that time has proven that good ideas without contributions do not get built.

For more information, see
or find us on Slack, in the #buddypress channel:

#21 @DJPaul
6 years ago

  • Milestone Awaiting Contributions deleted
  • Resolution set to maybelater
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.