【发布时间】:2016-05-04 10:35:18
【问题描述】:
我有一个提交到 php 文件的表单,该 php 文件将检查记录是否存在。如果存在,它将回显“已经存在”。在我的ajax“成功”中,它确实看到了“已经存在”,但是当我放置一个条件时它不起作用。例如,在我的 ajax 函数成功下,我放置了以下内容
$.ajax({
type: "GET",
data: $('#minifrm').serialize(),
url: "CRUD/myfile.php?check=" + para + "&freq=" + freq + "&expire=" + expire,
success: function (status) {
if (status.success == false) {
alert("Your details we not saved");
} else {
var checkstatus = status.toString();
if (checkstatus === 'Already Exists')
{
alert("You are here");
}
if (checkstatus === '')
{
alert("There is nothing");
}
}
}
});
目前它会回显“已经存在”并提醒“你在这里”,但如果它不存在,则不会提醒“什么都没有”。
【问题讨论】:
-
你从 php 文件返回什么?
-
你在这里设置值 checkstatus = 'Already Exists' 使它成为 checkstatus == 'Already Exists'
-
如果
status.success为假,它肯定会调用failed回调而不是success回调,对吧? -
如果您有一个具有
status.sucess的对象,那么status.toString()肯定会拥有该对象的.sucess部分吗?你能在 else 中对你的状态对象做一个console.log并显示结果吗
标签: javascript php ajax