我有以下jQuery:
$(document).ready(function() {
$('#login').click(function()
{
var username=$("#username").val();
var password=$("#password").val();
var dataString = 'username='+username+'&password='+password;
if($.trim(username).length>0 && $.trim(password).length>0)
{
$.ajax({
type: "POST",
url: "ajaxLogin.php",
data: dataString,
cache: false,
beforeSend: function(){ $("#login").val('Connecting...');},
success: function(data){
if(data)
{
$("body").load("<?php echo $_POST[$page]; ?>").hide().fadeIn(1500).delay(6000);
}
else
{
$('.login-block').shake();
$("#login").val('Login');
$("#error").html("<span style='color:#cc0000'>Error: Invalid username or password. </span>");
}
}
});
}
return false;
});
});
和ajaxLogin.php
:
<?php
include("db.php");
session_start();
if(isSet($_POST['username']) && isSet($_POST['password']))
{
$username=mysqli_real_escape_string($db,$_POST['username']);
$password=md5(mysqli_real_escape_string($db,$_POST['password']));
$result=mysqli_query($db,"SELECT ID FROM Students WHERE username='$username' and password='$password' UNION SELECT ID FROM Teachers WHERE username='$username' and password='$password' ");
$count=mysqli_num_rows($result);
$row=mysqli_fetch_array($result,MYSQLI_ASSOC);
if($count==1)
{
$_SESSION['login_user']=$row['ID'];
echo $row['ID'];
switch ($row['rank']) {
case 'student':
$page="student.html";
break;
case 'teacher':
$page="mainPage.html";
break;
}
}
}
?>
我正在尝试根据用户的排名将用户重定向到其他页面,这是我表格中的一列。到目前为止,我还没有设法使用排名,因为我一直在犯错误。其次,在我的jQuery成功部分,我只加载那个特定的页面,如何在等级上加载特定的页面?