jquery ajax - 如何成功使用响应

时间:2017-04-17 07:52:10

标签: javascript jquery ajax

page.php

$sqlQuery = "";
$result = $mysqli->query($sqlQuery);
if (mysqli_affected_rows($mysqli) > 0) {
    echo "success";
} else {
    echo "error";
}

我想成功使用响应文本,但if条件不起作用。 我如何使用if。

感谢您的帮助。

$.ajax({
    metod: "POST",
    url: "page.php",
    data: {data},
    success: function (response) {
        console.log(response); // It is working
        notification("success"); // It is working

        // response text is succes or error

        if (response == 'success') {
            btnLabel.html("DONE"); // It is not working
        } else if (response == 'error') {
            btnLabel.html("ERROR"); // It is not working
        }
    },
    error: function (err) {
        notification("error"); // It is working
    }
});

0 个答案:

没有答案