我有这个 jQuery 脚本
var dataString = "class_id="+class_id;
$.ajax({
type: "POST",
url: "page.php",
data: dataString,
success: function (msg) {
//stuck here
},
error: function () {
showNotification("error", "Could not process at this time, try again later."); //this is a function created by me (which works fine so I just left the code in here)
}
});
我的 PHP 输出是这样的
echo '{status:1,message:"Success"}';
或者
echo '{status:0,message:"Failure"}';
我在 jQuerysuccess: function(...)
部分尝试做的是检查状态是 0 还是 1,然后显示消息。
我试图做的是
success: function(text) {
if(parseInt(text.status) == 1) {
alert(text.message); // this is the success, the status is 1
} else {
alert(text.message); // this is the failure since the status is not 1
}
}
这不起作用,它只输出 else 语句,即使状态为 1