1 回答

TA貢獻(xiàn)1943條經(jīng)驗 獲得超7個贊
您不能直接從 php 重定向,因為您使用了 ajax,響應(yīng)將發(fā)送回success-functionajax?,F(xiàn)在,要解決這個問題,請執(zhí)行以下操作:
代碼:
if($row[0] > 0)
{
echo "success";//send back to ajax
}
else
{
echo "failed";//send back to ajax
}
并在您的 ajax 端檢查出現(xiàn)了哪些值,并根據(jù)該值重定向或顯示錯誤消息。
阿賈克斯代碼:
$('button#logBtn').click(function() {
if ($("#email_login").val() == "" || $("#pass_login").val() == "")
$("div#ack").html("please enter username or password");
else
$.post($("#frmLogin").attr("action"),
$("#frmLogin :input").serializeArray(),
function(data) {
var datas = $.trim(data); //remove whitespaces if any
if (datas == "success") {
window.location.href = "register.php"; //redirect
} else {
$("div#ack").html('<div class="alert alert-danger text-center" role="alert">Enter correct email or password!</div>'); //show error message
}
});
$("#frmLogin").submit(function() {
return false;
});
});
- 1 回答
- 0 關(guān)注
- 137 瀏覽
添加回答
舉報