[wp-hackers] Add Friend - Ajax - Failing & Don't See Why...

BenderisGreat greglancaster71 at gmail.com
Thu Oct 31 17:10:10 UTC 2013


Alright, A button that triggers an update_user_meta function, which adds the
user ID of profile user user to the meta field 'friends' belonging to the
user_meta of the currently active user.    I click add friend, and the
success action runs, but I get a "failed" alert.   I dont see any errors
popping up in the console.

Any ideas?  Also- Is there a way to view errors that occur off page, inside
funtions.php?  That would be an immense help.

<?php //friends
echo "<button id='add_friend' value=".$_current_member->ID.">Add
Friend</button>";
?>

<script type="text/javascript">
jQuery( document ).ready( function( $ ) { 
                $( '#add_friend').click( function( event ) { 
                var $button2 = $(this);
                var profileID = $(this).attr('value'); 
		var ajaxurl = '<?php echo admin_url('admin-ajax.php') ?>';

                var data = { 
                        'action': 'my_add_friend_action', 
                        'profileID': profileID  } 

                $.post( 
                        ajaxurl, 
                        data,
                        function ( response ) { 
                                if ( ! response.success ) { 
                                        alert( 'Failure!' ); } 
                                       						
		$button2.html("FRIEND ADDED");

                        } 
                ); 
        }); 
}); 

and the wordpress function that handles this:

add_action('wp_ajax_my_add_friend_actionn', 'my_add_friend_action');
add_action('wp_ajax_nopriv_my_add_friend_action', 'my_add_friend_action');
function my_add_friend_action() {
	global $wpdb, $current_user;
        get_currentuserinfo();
		
	$profileID = $_POST['profileID'];
	$userID = $_POST['userID'];
	
//	activity_tracker($current_user, 'added_friend', 'prof');
	update_user_meta( $user->ID, 'friends', $profileID );
	
	$response = array( 'success' => true ); 
		
	wp_send_json_success($response);

	die();
}



--
View this message in context: http://wordpress-hackers.1065353.n5.nabble.com/Add-Friend-Ajax-Failing-Don-t-See-Why-tp42686.html
Sent from the Wordpress Hackers mailing list archive at Nabble.com.


More information about the wp-hackers mailing list