我是网络技术的新手,试图通过例子来建立。这个问题似乎是反复出现的。但是,我无法获得正确的语法/方法。
我试图读取由ajax调用(action.php)设置的值,并在客户端(js)上使用它。下面是我的尝试
$.ajax({
type: "POST",
url: "/crm/action.php",
data: form,
success: function(data){
alert(data.error);
},
error: function () {
myalert("DATABASE ERROR","X Record not saved. if this error persists, contact your system administrator");
}
});
和action.php只是尝试设置变量"error"如下
$error = 1;
到目前为止,我所有的尝试都返回"undefined"
将action.php更改为以下内容:
die(json_encode(['error' => 1]));
确保没有任何其他输出,除了上面的