我正在尝试使用 AJAX 和 PHP 创建登录以更流畅地显示错误消息。
我的 HTML
<form>
<input type="email" placeholder="Email Address" id="loginMail" name="loginMail" class="text">
<input type="password" placeholder="Password" id="pass" name="pass" class="text"><br><br>
<input type="checkbox" name="autologin" value="1"> Remember me: | <a href="#">Forgot password?</a><br/><br>
<input type="submit" name="submitLogin" id="submitLogin" class="submit" value="Sign In"><br />
</form>
我的Javascript:
$('#submitLogin').click(function()
{
var email = $('#loginMail').val();
var pass = $('#pass').val();
$.post('login.php',
{email: email, pass: pass},
function(data)
{
alert(data);
});
});
我的 PHP
<?php
include('database.php');
$pdo = new database();
$email = $_POST['email'];
$pass = md5($_POST['pass']);
#$email = 'web.de';
#$pass = 'pw';
$qry = $pdo->pdo->prepare("SELECT * FROM userbasics WHERE email = :email AND pass = :pass");
$qry->bindParam(':email', $email);
$qry->bindParam(':pass', $pass);
$qry->execute();
#$result = $qry->fetchAll();
$count = $qry->rowCount();
if($count == 1){
echo "Eingeloggt!";
header("Location: http://www.google.de");
}
else{
echo "E-Mailadresse oder Passwort falsch!";
}
/*foreach($result as $row){
echo $row['email'];
}*/
?>
当我只是用定义的数据调用 PHP 脚本时,它会返回我应该做的事情。所以我猜这是Javascript-Part的一个问题。有什么建议么?