我有这段代码用于登录 jQuery mobile。但是,它不起作用,什么也没有发生......当我提交时,我返回到同一页面。
就像他不输入php文件一样。
这是ajax脚本:
<script>
$(document).ready(function(){
$("#loginform").submit( function(){
$.post('LoginExcution.php',
$(this).serialize(), function(data){ $("#errorm").html(data)}};
return false;
});
</script>
这是html:
<div data-role="page" id="login">
<div data-theme="a" data-role="header">
</div>
<div data-role="content" style="padding: 15px">
<div style="text-align:center">
<img style="width: 50%; height: 50%" src="logo.jpg" />
</div>
<form id="loginform" method='post'>
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<label for="textinput2" style="text-align:right">
Email:
</label>
<input id="textinput2" name="login" value="" type="text"/>
</fieldset>
</div>
<div data-role="fieldcontain">
<fieldset data-role="controlgroup">
<label for="textinput3" style="text-align:right">
Password: </label>
<input id="textinput3" name="password" value="" type="password"/>
</fieldset>
</div>
<h3 id="errorm"> <?php if (isset($_GET['msg'])){
echo "Invalid username or password";
}
?></h3>
<input type="submit" name="submit" id="submit" data-inline="true" data- icon="arrow-l" data-iconpos="left" value="login"/>
</form>
这里是LoginExecution.php:
//Sanitize the POST values
$login = $_POST['login'];
$password = $_POST['password'];
$aqry="SELECT * FROM admin WHERE name='$login' AND password='".$_POST['password']."'";
$employeeresult=mysql_query($eqry);
$adminresult=mysql_query($aqry);
if( $employeeresult || $adminresult ){
//Check whether the query was successful or not
if(mysql_num_rows($adminresult) == 1) {
//Login Successful
$member = mysql_fetch_assoc($adminresult);
$_SESSION['MEMBER_ID'] = $member['AdID'];
$_SESSION['NAME'] = $member['name'];
header("location: mlogin.php");
exit();
}
else {
//Login failed
header("Location: mobile/mlogin.php?msg=invalid%20name%20or%20password");
exit();
}
谢谢