输入正确的用户名/密码后,会出现登录成功。我想在成功登录后重定向到不同的页面,但 window.location.href 不起作用。
索引.html
<form id="myFormlogin" action="login.php" method="POST">
Email:
<input type="text" name="usernamelogin" />
<br />Password:
<input type="password" name="passlogin" />
<br />
<button id="login">login</button>
</form>
<div id="ack"></div>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script type="text/javascript" src="my_script.js"></script>
登录.php
<?php
include_once('db.php');
$username = mysql_real_escape_string($_POST["usernamelogin"]);
$password = mysql_real_escape_string(md5($_POST["passlogin"]));
$sql = "SELECT * FROM registered_users WHERE username='$username' and password='$password'";
$result = mysql_query($sql);
if ($result) {
echo "login success";
} else {
echo "Wrong Username or Password";
}
?>
脚本.js
("#login").click( function() {
if( $("#usernamelogin").val() == "" || $("#passlogin").val() == "" )
$("#ack").html("Username/Password are mandatory fields -- Please Enter.");
else
window.location.href = "http://jsfiddle.net/";
});