<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <form action="php/test.php" method="post"> <input type="text" name="username" id="username" value="" /><span></span> <input type="password" name="pwd" id="pwd" value="" /><span></span> <input type="button" value="" id="submit"/> </form> <script src="js/jquery-2.2.1.min.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> $("#username").blur(function(){ $.ajax({ type:"post", url:"php/test.php", async:true, success:function(msg){ var infoList = msg.split("&"); var nameList = []; for(var j=0;j<infoList.length;j++){ var oName = infoList[j].split("@")[0]; nameList.push(oName); } for(var i=0;i<nameList.length;i++){ if(nameList[i]==$("#username").val()){ $("span").eq(0).html("该账户存在"); return false; }else{ $("span").eq(0).html("该账户不存在"); } } } }); }) $("#submit").click(function(){ $.ajax({ type:"post", url:"php/test.php", async:true, success:function(msg){ var infoList = msg.split("&"); var nameList = []; var pwdList = []; for(var j=0;j<infoList.length;j++){ var oName = infoList[j].split("@")[0]; var oPwd = infoList[j].split("@")[1]; nameList.push(oName); pwdList.push(oPwd); } for(var i=0;i<nameList.length;i++){ if(nameList[i]==$("#username").val()){ if(pwdList[i]!=$("#pwd").val()){ $("span").eq(1).html("密码错误!"); return false; }else{ $("form").submit(); window.location.href = "php/test.php"; } } } } }); }) </script> </body> </html>
php文件:test.php
<?php echo "syz@123&ketty@234&tom@345&jerry@456"; ?>