管理员用户的 Wordpress Ajax returns 数据正确,但非管理员的 returns 整个主页
Wordpress Ajax returns data correctly for admin user, but returns the entire home page for non-admins
所以正如上面的主题所述,我有一个 2 字段表单,它通过 ajax 将两个变量发布到通过 WP_User_Query 查询的 php 文件。然后将返回的数据显示在页面上。以管理员身份登录时,整个过程完美运行。当以订阅者身份登录时会出现问题 & 运行 相同的脚本。返回的结果是加载到我的 "results" div 中的整个主页。我检查了控制台,它显示 "XHR Loaded (admin-ajax.php - 302 Moved Temporarily" 以及另一个显示 "XHR Loaded (websitenamehere) - 301 Moved Permanently".
任何帮助将不胜感激,甚至为解决问题指明正确的方向。这是我的 php 代码的前几行,因为我觉得这可能是问题所在。
//Add Activity to Database (AJAX)
add_action("wp_ajax_county_search", "county_search");
add_action("wp_ajax_nopriv_county_search", "my_must_login_county_search");
function nceda_county_search() { ...
这是我排队的 js 文件和 ajax 本地化...
//Enqueue Scripts
add_action( 'init', 'my_script_enqueuer' );
function my_script_enqueuer() {
wp_register_script( "member_search_script", WP_PLUGIN_URL.'/member-search/js/member-search.js', array('jquery') );
wp_localize_script( 'member_search_script', 'myAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' )));
wp_enqueue_script( 'member_search_script' );
}
admin_url
http://codex.wordpress.org/Function_Reference/admin_url
The admin_url template tag retrieves the url to the admin area for the
current site with the appropriate protocol, 'https' if is_ssl() and
'http' otherwise. If scheme is 'http' or 'https', is_ssl() is
overridden.
Parameters $path (string) (optional) Path relative to the admin url.
Default: None $scheme (string) (optional) The scheme to use. Default
is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or
'https' can be passed to force those schemes. The function uses
get_site_url(), so allowed values include any accepted by that
function. Default: 'admin'
查看模式参数
(string) (optional) Scheme to give the site url context. Currently
'http', 'https', 'login', 'login_post', 'admin' or 'relative'.
尝试使用 'http' 或 null
或更好地使用site_url()
所以正如上面的主题所述,我有一个 2 字段表单,它通过 ajax 将两个变量发布到通过 WP_User_Query 查询的 php 文件。然后将返回的数据显示在页面上。以管理员身份登录时,整个过程完美运行。当以订阅者身份登录时会出现问题 & 运行 相同的脚本。返回的结果是加载到我的 "results" div 中的整个主页。我检查了控制台,它显示 "XHR Loaded (admin-ajax.php - 302 Moved Temporarily" 以及另一个显示 "XHR Loaded (websitenamehere) - 301 Moved Permanently".
任何帮助将不胜感激,甚至为解决问题指明正确的方向。这是我的 php 代码的前几行,因为我觉得这可能是问题所在。
//Add Activity to Database (AJAX)
add_action("wp_ajax_county_search", "county_search");
add_action("wp_ajax_nopriv_county_search", "my_must_login_county_search");
function nceda_county_search() { ...
这是我排队的 js 文件和 ajax 本地化...
//Enqueue Scripts
add_action( 'init', 'my_script_enqueuer' );
function my_script_enqueuer() {
wp_register_script( "member_search_script", WP_PLUGIN_URL.'/member-search/js/member-search.js', array('jquery') );
wp_localize_script( 'member_search_script', 'myAjax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' )));
wp_enqueue_script( 'member_search_script' );
}
admin_url
http://codex.wordpress.org/Function_Reference/admin_url
The admin_url template tag retrieves the url to the admin area for the current site with the appropriate protocol, 'https' if is_ssl() and 'http' otherwise. If scheme is 'http' or 'https', is_ssl() is overridden.
Parameters $path (string) (optional) Path relative to the admin url. Default: None $scheme (string) (optional) The scheme to use. Default is 'admin', which obeys force_ssl_admin() and is_ssl(). 'http' or 'https' can be passed to force those schemes. The function uses get_site_url(), so allowed values include any accepted by that function. Default: 'admin'
查看模式参数
(string) (optional) Scheme to give the site url context. Currently 'http', 'https', 'login', 'login_post', 'admin' or 'relative'.
尝试使用 'http' 或 null
或更好地使用site_url()