Php 尽管Ajax调用成功,Wordpress Ajax始终返回0
我试图从Wordpress的Php 尽管Ajax调用成功,Wordpress Ajax始终返回0,php,jquery,ajax,wordpress,Php,Jquery,Ajax,Wordpress,我试图从Wordpress的wp\u users表中读取(通过Ajax请求),并在页面中查看它。我需要你的帮助,让我知道我做错了什么,通过使用Ajax成功打印根电子邮件地址 我的JavaScript ajax调用是: function ajaxTest () { // Creating the URL that Ajax must refer to. var ajaxurl = "<?php echo admin_url( '
wp\u users
表中读取(通过Ajax请求),并在页面中查看它。我需要你的帮助,让我知道我做错了什么,通过使用Ajax成功打印根电子邮件地址
我的JavaScript ajax调用是:
function ajaxTest ()
{
// Creating the URL that Ajax must refer to.
var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' ); ?>";
// Do Ajax call.
jQuery.ajax({
url: ajaxurl,
type: "POST",
data: { action: "wp_ajax_tester" },
complete: function( xhr, status ){
console.log("Request completion status: " + status);
},
success: function (response){
console.log("result: " + response);
},
error: function(errorThrown){
console.log("error: " + errorThrown);
}
});
}
我想打印出根电子邮件地址,但这是在浏览器控制台中打印的地址:result: 0
Request completion status: Successful
我正在使用Wordpress自己的jQuery,将下面的一行放在文件标题部分:
<?php wp_enqueue_script("jquery"); ?>
<?php wp_head(); ?>
这是针对Ajax的,请从操作中删除wp\u Ajax\uu
示例代码
function ajaxTest ()
{
// Creating the URL that Ajax must refer to.
var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' ); ?>";
// Do Ajax call.
jQuery.ajax({
url: ajaxurl,
type: "POST",
data: { action: "tester" },
complete: function( xhr, status ){
console.log("Request completion status: " + status);
},
success: function (response){
console.log("result: " + response);
},
error: function(errorThrown){
console.log("error: " + errorThrown);
}
});
}
功能测试()
{
//创建Ajax必须引用的URL。
var ajaxurl=“”;
//打电话。
jQuery.ajax({
url:ajaxurl,
类型:“POST”,
数据:{action:“tester”},
完成:功能(xhr,状态){
控制台日志(“请求完成状态:+状态”);
},
成功:功能(响应){
console.log(“结果:+响应”);
},
错误:函数(错误抛出){
log(“错误:+errorshown”);
}
});
}
您是否直接在您的数据库上运行该查询以确保它实际返回一些结果?是的,先生,结果是没有可用的用户
字段。一个小小的错误就毁了我的一天。该字段名为user\u login
,我想这里需要一些负面信息。非常感谢你给我这个解决方案的提示。
function ajaxTest ()
{
// Creating the URL that Ajax must refer to.
var ajaxurl = "<?php echo admin_url( 'admin-ajax.php' ); ?>";
// Do Ajax call.
jQuery.ajax({
url: ajaxurl,
type: "POST",
data: { action: "tester" },
complete: function( xhr, status ){
console.log("Request completion status: " + status);
},
success: function (response){
console.log("result: " + response);
},
error: function(errorThrown){
console.log("error: " + errorThrown);
}
});
}