Get user ID from dropdown and show content related
The admin has a drop down of all the current users in the system.
On a particular page it loads content related to that user when they are logged and it’s based off their user ID.
What I’m trying to do is when the admin clicks another users in the drop down the content in that area changes according to the new users ID.
I can get the jQuery to get the users ID and then send it via Ajax. However what I get back is just the number with a 0 behind it. I’ve checked and that means something went wrong. But can’t understand what since it’s returning that value…
HTML
- <div class="results_wrapper">
- <div class="results_content">
- content
- </div>
- </div>
JQUERY
- jQuery('.users_with_email').on('change',function(){
- var userID = jQuery(".users_with_email option:selected").val();
- console.log(userID);
- $.ajax({
- url: post_ajax.ajax_url,
- type: 'post',
- cache: false,
- data : {
- action : 'ajax_user_results',
- userID : userID
- },
- beforeSend: function() {
- jQuery('.results_wrapper').find( '.results_content' ).remove();
- },
- success: function( html ) {
- jQuery('.user_id').html( html );
- jQuery('.results_wrapper').load(document.URL + ' .results_content');
- }
- });
- });
PHP
- add_action( 'wp_ajax_nopriv_ajax_user_results', 'ajax_user_results' );
- add_action( 'wp_ajax_ajax_user_results', 'ajax_user_results' );
- function ajax_user_results() {
- $chosen_user = $_POST['userID'];
- }
PHP Outputted back