【发布时间】:2015-07-16 16:18:54
【问题描述】:
回调消息为 0,我不知道为什么。
我试图尽可能地关注this tutorial,但我显然遗漏了一些东西。
在谷歌浏览器的网络中,每次点击触发表单提交的按钮,我看到admin-ajax.php正在被调用,状态为200。
我做错了什么?
<form method="POST" action="member-update" enctype="multipart/form-data">
<!-- ... bunch of inputs and stuff in here -->
</form>
error_reporting(-1);
ini_set('display_errors', 'On');
$tm = new TeamManager();
add_action('wp_ajax_member-update', 'member_update');
function member_update() {
echo json_encode("TEST ... ");
}
jQuery('.member-update-button').click(function () {
var parentForm = jQuery(this).closest('form');
var postData = parentForm.serializeArray();
jQuery.ajax({
url: "<?php echo admin_url('admin-ajax.php'); ?>",
data: {
action: 'member_update',
postData: postData
},
type: "POST",
dataType: 'json',
success: function (retmsg) {
alert(retmsg); // test for now
},
error: function () {
alert("error"); // test for now
}
});
});
【问题讨论】:
-
您告诉 JS 期待 json,但您在 PHP 中设置了最大错误报告/显示错误。这意味着 ANY php 警告/错误将成为输出的一部分,并被视为 json 语法错误。
-
你在哪里
echo什么?在member_update()???如果是,那么您在哪里调用member_update()函数? -
只是在黑暗中拍摄,但不应该是
data: {action: 'wp_ajax_member-update', postData: postData},吗?
标签: javascript php jquery ajax wordpress