Php AJAX不返回任何内容-Wordpress
我的代码基于此处接受的答案: header.phpPhp AJAX不返回任何内容-Wordpress,php,jquery,ajax,wordpress,Php,Jquery,Ajax,Wordpress,我的代码基于此处接受的答案: header.php <?php $admin_ajax_path = ABSPATH . 'wp-admin/admin-ajax.php'; ?> <script> var absAjaxPath = "<?php echo $admin_ajax_path; ?>"; </script> 我的js文件 jQuery('.list-group-item').click(function() { var
<?php $admin_ajax_path = ABSPATH . 'wp-admin/admin-ajax.php'; ?>
<script>
var absAjaxPath = "<?php echo $admin_ajax_path; ?>";
</script>
我的js文件
jQuery('.list-group-item').click(function() {
var id = jQuery(this).attr('id');
alert(id);
jQuery.ajax({
url: 'http://sub.domain.com/wp-admin/admin-ajax.php',
url: absAjaxPath, //this one returns a not found error
data: {'action' : 'ajax_request', 'fn': 'getUserMeta', 'id': id},
dataType: 'json',
success: function(data) {
//We expect a JSON encoded array here, not an HTML template.
alert(data);
}
});
return false;
});
单击id设置为2的元素后,alertid将触发。我用这个id设置了一个用户。除此之外,什么也没有发生。ajax成功函数中的alertdata是否应该触发?添加骰子;或退出;到PHP函数的最后一行,通过AJAX调用该函数以防止返回0。尝试删除数据类型:“json”
让ajax自动检测您检查开发人员控制台了吗?服务器的响应是什么?我直到现在才知道。非常感谢。它返回0现在找出代码返回的部分以及0似乎是echo$output。。。奇怪的是,我又加了一句“你好”;而不是返回$theMeta;而不是它又回来了。我想知道0是从哪里来的。但这是否意味着:$theMeta=get_user_meta$id,'tel',true;这不是获取用户元的方法吗?这是抄本上说的。也许@OhGod为什么能帮上忙呢。你是说在归还$theMeta?是的。在我看来,死亡和退出仍然返回0应该在ajax\u handle\u请求中。
jQuery('.list-group-item').click(function() {
var id = jQuery(this).attr('id');
alert(id);
jQuery.ajax({
url: 'http://sub.domain.com/wp-admin/admin-ajax.php',
url: absAjaxPath, //this one returns a not found error
data: {'action' : 'ajax_request', 'fn': 'getUserMeta', 'id': id},
dataType: 'json',
success: function(data) {
//We expect a JSON encoded array here, not an HTML template.
alert(data);
}
});
return false;
});