未显示成功和失败消息尽管数据已插入数据库,但始终显示另一个错误

时间:2017-11-05 07:29:04

标签: php ajax

$.ajax({
    type: "POST",
    url: "addDB.php",
    data: "name=" + name + "&id=" + id + "&college=" + college + "&branch=" + branch + "&year=" + year + "&phone=" + phone + "&email=" + email + "&event=" + event,
    success: function(msg) {
        $("#overlay").css("display", "none");
        if (msg == 'error') {
            alert("Some error occurred");
        } else if (msg == 'exists') {
            alert("This email id is already registered.");
        } else if (msg == 'done') {
            alert("Registration Successfull");
        } else {
            alert("Some another error occurred");
        }
    }

});

1 个答案:

答案 0 :(得分:0)

您收到一条成功消息,但您没有将您的msg转换为addDB.php中后端的有效JSON对象。

在addDB.php中尝试此操作,无论您在何处定义“msg”

json_encode(['msg' => 'done']);
exit();