Forum Replies Created
-
Btw from the log
[06-Dec-2014 18:02:54] PHP Fatal error: Call to a member function members() on a non-object in /home/public_html/wordpress/wp-content/plugins/buddypress/bp-groups/bp-groups-template.php on line 2815
Is this right then?
function my_action_callback() { $names = array(); $whatever = intval( $_POST['whatever'] ); while ( bp_group_members() ) : bp_group_the_member(); array_push($names, bp_get_group_member_name()); endwhile; //$rep2 = array( $_POST['whatever'] . ' successful!' ); echo json_encode($names); die(); }
The plugin is run only in a group view.
Hi
I figured out that it’s the while loop that’s stopping the php function from responding properly
While this works just fine:
function my_action_callback() { global $wpdb; $names = array(); $whatever = intval( $_POST['whatever'] ); //while ( bp_group_members() ) : bp_group_the_member(); //$name = bp_group_member_name() ; //array_push($names, $name); //endwhile; $rep2 = array( $_POST['whatever'] . ' successful!' ); echo json_encode($rep2); die(); }
This stops the click from alerting anything
function my_action_callback() { global $wpdb; $names = array(); $whatever = intval( $_POST['whatever'] ); while ( bp_group_members() ) : bp_group_the_member(); $name = bp_group_member_name() ; array_push($names, $name); endwhile; $rep2 = array( $_POST['whatever'] . ' successful!' ); echo json_encode($rep2); die(); }
Any idea why is the loop wrong there?
Any help highly appreciated
Thank for the reply.
I tried it but then even the alert doesn’t show when I change the code.
This is the entire code: [ edited: see below for link to code ]
Thanks for that. I read through it and I wanted to add the example function for admin footer to my plugin to check how it works but it crashes wordpress when I try to access the Dashboard.
Internal Server Error
The server encountered an internal error or misconfiguration and was unable to complete your request.
I used this code:
<?php add_action( 'admin_footer', 'my_action_javascript' ); // Write our JS below here function my_action_javascript() { ?> <script type="text/javascript" > jQuery(document).ready(function($) { var data = { 'action': 'my_action', 'whatever': 1234 }; // since 2.8 ajaxurl is always defined in the admin header and points to admin-ajax.php $.post(ajaxurl, data, function(response) { alert('Got this from the server: ' + response); }); }); </script> <?php }
<?php add_action( 'wp_ajax_my_action', 'my_action_callback' ); function my_action_callback() { global $wpdb; // this is how you get access to the database $whatever = intval( $_POST['whatever'] ); $whatever += 10; echo $whatever; die(); // this is required to terminate immediately and return a proper response }
Any ideas what goes wrong here?