我正在尋找通過Wordpress通過Ajax將用戶數(shù)據(jù)作為字符串返回的方式iv掌握了基本概念的PHP這放在我的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 . "\n"; echo 'User roles: ' . implode(', ', $user_info->roles) . "\n"; echo 'User ID: ' . $user_info->ID . "\n";}jQuery / JS $.ajax({ url: "http://www.example.com/", method: "POST", data: { getbyID: "23", }, success: function(response){ console.log(response); //example script logic here } })控制臺日志結(jié)果是正確的,但是它還會記錄許多未包含在其中的html元素。如我不完全清楚為什么。這是一個完整的小例子Username: someusernameUser roles: subscriberUser ID: 23<!DOCTYPE html><html><div id="loadtheme" class="loadtheme"></div><head>etc etc etc....有什么想法嗎?
使用Ajax調(diào)用的wordpress PHP
繁華開滿天機(jī)
2021-04-06 14:18:30