引用的是jquery-2.1.4.min.js,数据提交成功了,但是不跳转。数据库测试也有记录。
JS代码function Login() { $.ajax({ type: "POST",//方法 url: "aph/logingo.php" ,//表单接收url data: $('#form1').serialize(), success: function (data) { var result=document.getElementById("Result"); //提交成功 result.innerHTML=data[0].result; if (data[0].result == "登陆成功") { result.innerHTML="登陆成功"; setTimeout("window.location.href='http://www.zaijiapc.com'",2000); }else if (data[0].result == "fail") { result.innerHTML="<a style='color:red'>账号或密码错误</a>"; } }, error : function(data) { //提交失败的提示词或者其他反馈代码 var result=document.getElementById("Result"); result.innerHTML="<a style='color:red'>网络连接失败</a>"; } }); } PHP代码 <?php//error_reporting(-1); //打印出所有的 错误信息header("Content-type:application/json;chartset=uft-8");
$username = $_POST["username"];//获取表单POST过来的用户名$passs = $_POST["pass"];//获取表单POST过来的密码//$addkey = $_POST['logcode']; //8位KEY //表单过滤$user = trim($username);//过滤空格$psw = trim($passs);//过滤空格 //开始判断if($user == "" && $psw == ""){ echo "[{\"result\":\"<a style='color:red'>账号和密码都没填呢!</a>\"}]";}else if ($user == "") { echo "[{\"result\":\"<a style='color:red'>账号还没填呢</a>\"}]";}else if ($psw == "") { echo "[{\"result\":\"<a style='color:red'>密码还没填呢</a>\"}]";}else{
//校验MD5密码 $md5psw = MD5($psw); include_once($_SERVER['DOCUMENT_ROOT'].'/config/db.php'); //链接数据库配置文件$sql = "SELECT * FROM add_user WHERE username='$_POST[username]' and pass='$md5psw'";
$result = $db->query($sql);$row = $result->fetch_assoc();session_start();$_SESSION['username'] = $row['username']; $_SESSION['userid'] = $row['id'];
if ($row) { echo "[{\"result\":\"验证成功\"}]"; }else{ echo "[{\"result\":\"fail\"}]"; }}
?>