Im looking to return user data back as a string through ajax with wordpress
Iv got the basic concept down
PHP
this is placed in my functions.php
add_action('template_redirect', 'edit_user_concept'); function edit_user_concept(){ $id = $_POST['getbyID']; $user_info = get_userdata($id); echo 'Username: ' . $user_info->user_login . " "; echo 'User roles: ' . implode(', ', $user_info->roles) . " "; echo 'User ID: ' . $user_info->ID . " "; }
Jquery/JS
$.ajax({
url: "http://www.example.com/",
method: "POST",
data: {
getbyID: "23",
},
success: function(response){
console.log(response);
//example script logic here
}
})
the console log result is correct how ever its also logging lots of html elements that are not included in this. Such as
im not exactly sure why.
here is a small example to large to post in its full
Username: someusername
User roles: subscriber
User ID: 23
<!DOCTYPE html>
<html lang="en-US">
<div id="loadtheme" class="loadtheme"></div>
<head>
etc etc etc....
Any thoughts?
</div>