This article mainly introduces the very practical ajax user registration module in detail, which has certain reference value. Interested friends can refer to it
The use of ajax technology in website design It is already very common, especially in interactive websites, ajax technology is even more indispensable. Ajax technology can be seen in almost all interactive website applications, large websites such as membership registration, small websites such as non-refresh Pagination technology gives website visitors a better user experience. In local website design, if there is an error in browsing a certain part, there is no need to refresh the entire web page. The most widely used part is the no-refresh verification of member registration, etc., no refresh Pagination, view more without refreshing, query whether the content in the database exists without refreshing, etc.
The following is the ajax user registration module. This ajax registration module is very practical. You only need to expand it according to your own needs. The check.php file is a query data file, just change the query content to your own. It should be easy to understand. You can download and verify it if necessary.
check.php
<?php header("Content-Type:text/html;charset=gb2312"); @mysql_connect('localhost','root','ebaeba') or die("数据库服务器连接失败"); @mysql_select_db("test") or die("数据库不存在或不可用"); $uname = $_GET['userName']; //下面进行数据库查询 查找是不是有这一个用户 //如果没有查找到这个用户名 $sql="select * from t1 where name='".$uname."'"; $query=mysql_query($sql); $row=mysql_fetch_object($query); if(strlen($uname)<6||strlen($uname)>20) { $msg="用户名必须是6至20个字符."; } else { if($row==false) { $msg="该用户名有效,可以使用!"; } else { $msg="对不起,此用户名已经存在,请更换用户名注册!"; } } echo $msg ; ?>
reg.php
<%@page language="java" contentType="text/html;charset=gb2312"%> <! DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN" "http://www.w3.org/TR/REC-html140/strict.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>AJAX用户注册演示程序</title> <script language="javascript" type="text/javascript"> <!-- //创建函数 function createXMLHTTP() { var request; var browser = navigator.appName; //使用IE,则使用XMLHttp对象 if(browser == "Microsoft Internet Explorer") { var arrVersions = ["Microsoft.XMLHttp", "MSXML2.XMLHttp.4.0", "MSXML2.XMLHttp.3.0", "MSXML2.XMLHttp","MSXML2.XMLHttp.5.0"]; for (var i=0; i < arrVersions.length; i++) { try { //从中找到一个支持的版本并建立XMLHttp对象 request = new ActiveXObject(arrVersions[i]); return request; } catch (exception) { //忽略,继续 } } } else { //否则返回一个XMLHttpRequest对象 request = new XMLHttpRequest(); if(request.overrideMimeType) { request.overrideMimeType('text/xml'); } return request; } } //全局XMLHTTP对象实例变量 var http = createXMLHTTP(); //发送请求 function chkUser() { var url = "check.php"; //请求"CheckUserName" ServLet var name = document.getElementById("userName").value; url += ("?userName="+escape(name)+"&oprate=chkUser"); http.open("GET",url,true); http.onreadystatechange = ProcessHttpResponse; http.send(null); return ; } //处理响应 function ProcessHttpResponse() { if(http.readyState == 4) { if(http.status == 200) { var xmlDocument = http.responseXML; if(http.responseText!="该用户名有效,可以使用!") { //返回的信息动态显示 document.getElementById("showStr").style.display = ""; document.getElementById("userName").style.background= "#FF0000"; document.getElementById("showStr").innerText = http.responseText; } else { document.getElementById("userName").style.background= "#FFFFFF"; document.getElementById("showStr").style.display = ""; document.getElementById("showStr").innerText = http.responseText; } } else { alert("你所请求的页面发生异常,可能会影响你浏览该页的信息!"); alert(http.status); } } } //检验输入密码 function chkpassword() { var m=document.form1; if(m.password.value.length>20 || m.password.value.length<6 ) { document.getElementById("passwordStr").style.display = ""; document.getElementById("password").style.background= "#FF0000"; document.getElementById("passwordStr").innerText = "对不起,密码必须为英文字母、数字或下划线,长度为6~20!"; } else { document.getElementById("password").style.background= "#FFFFFF"; document.getElementById("passwordStr").style.display = "none"; } } //验证两次密码是否一致 function chkconfirmPassword() { var m=document.form1; if (m.password.value != m.confirmPassword.value) { document.getElementById("confirmPasswordStr").style.display = ""; document.getElementById("confirmPassword").style.background= "#FF0000"; document.getElementById("confirmPasswordStr").innerText = "对不起,密码与重复密码不一致!"; } else { document.getElementById("confirmPassword").style.background= "#FFFFFF"; document.getElementById("confirmPasswordStr").style.display = "none"; } } //验证Email是否有效 function chkEmail() { var m=document.form1; var email = m.email.value; //正则表达式 var regex = /^([a-zA-Z0-9_-])+@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-])+/; var flag = regex.test(email); if(!flag) { document.getElementById("emailStr").style.display = ""; document.getElementById("email").style.background= "#FF0000"; document.getElementById("emailStr").innerText = "对不起,邮箱地址无效!"; } else { document.getElementById("email").style.background= "#FFFFFF"; document.getElementById("emailStr").style.display = "none"; } } //提交检查函数 function SubmitCheck() { var m=document.form1; if(m.userName.value.length==0) { alert("对不起,用户名必须为英文字母、数字或下划线,长度为5~20。"); m.userName.focus(); return false; } if(m.password.value.length==0) { alert("对不起,密码必须为英文字母、数字或下划线,长度为5~20。"); m.password.focus(); return false; } if (m.password.value != m.confirmPassword.value) { alert("对不起,密码与重复密码不一致!"); m.confirmPassword.focus(); return false; } if(m.email.value.length==0) { alert("对不起,邮箱地址不能为空!!"); m.email.focus(); return false; } m.submit(); } //--> </script> <body > <form name="form1" method="post" action="register.php"> <h3 id="Ajax用户注册程序">Ajax用户注册程序</h3> <table align="center" width="500" border="1" > <tr> <td><font color="red">*</font></td> <td width="100">用户帐号:</td> <td><input type="text" name="userName" maxlength="20" style="background=#FFFFFF" onBlur="chkUser()"></td> <td><p id="showStr" style="background-color:#FF9900;display:none"></p></td> </tr> <tr> <td><font color="red">*</font></td> <td>用户密码:</td> <td align="left"><input type="password" name="password" maxlength="22" style="background=#FFFFFF" onBlur="chkpassword()"/> </td> <td><p id="passwordStr" style="background-color:#FF9900;display:none"></p></td> </tr> <tr> <td><font color="red">*</font></td> <td>确认密码:</td> <td><input type="password" name="confirmPassword" maxlength="20" style="background=#FFFFFF" onBlur="chkconfirmPassword()"/></td> <td><p id="confirmPasswordStr" style="background-color:#FF9900;display:none"></p></td> </tr> <tr> <td><font color="red">*</font></td> <td>Email:</td> <td><input type="text" name="email" maxlength="100" style="background=#FFFFFF" onBlur="chkEmail()"></td> <td><p id="emailStr" style="background-color:#FF9900;display:none"></p></td> </tr> </table> <p align="center"> <input type="button" name="ok" value=" 确定 " onClick="SubmitCheck()"> <input type="reset" name="reset" value=" 取消 "> </form> </p> </body> </html>
The above is what I compiled for everyone. I hope it will be useful to you in the future. Everyone is helpful.
Related articles:
A brief discussion on ajax request technology
Configuration of Ajax global loading box (Loading effect)
Ajax loading chrysanthemum loding effect
The above is the detailed content of Very practical ajax user registration module. For more information, please follow other related articles on the PHP Chinese website!

JavaScript's application in the real world includes front-end and back-end development. 1) Display front-end applications by building a TODO list application, involving DOM operations and event processing. 2) Build RESTfulAPI through Node.js and Express to demonstrate back-end applications.

The main uses of JavaScript in web development include client interaction, form verification and asynchronous communication. 1) Dynamic content update and user interaction through DOM operations; 2) Client verification is carried out before the user submits data to improve the user experience; 3) Refreshless communication with the server is achieved through AJAX technology.

Understanding how JavaScript engine works internally is important to developers because it helps write more efficient code and understand performance bottlenecks and optimization strategies. 1) The engine's workflow includes three stages: parsing, compiling and execution; 2) During the execution process, the engine will perform dynamic optimization, such as inline cache and hidden classes; 3) Best practices include avoiding global variables, optimizing loops, using const and lets, and avoiding excessive use of closures.

Python is more suitable for beginners, with a smooth learning curve and concise syntax; JavaScript is suitable for front-end development, with a steep learning curve and flexible syntax. 1. Python syntax is intuitive and suitable for data science and back-end development. 2. JavaScript is flexible and widely used in front-end and server-side programming.

Python and JavaScript have their own advantages and disadvantages in terms of community, libraries and resources. 1) The Python community is friendly and suitable for beginners, but the front-end development resources are not as rich as JavaScript. 2) Python is powerful in data science and machine learning libraries, while JavaScript is better in front-end development libraries and frameworks. 3) Both have rich learning resources, but Python is suitable for starting with official documents, while JavaScript is better with MDNWebDocs. The choice should be based on project needs and personal interests.

The shift from C/C to JavaScript requires adapting to dynamic typing, garbage collection and asynchronous programming. 1) C/C is a statically typed language that requires manual memory management, while JavaScript is dynamically typed and garbage collection is automatically processed. 2) C/C needs to be compiled into machine code, while JavaScript is an interpreted language. 3) JavaScript introduces concepts such as closures, prototype chains and Promise, which enhances flexibility and asynchronous programming capabilities.

Different JavaScript engines have different effects when parsing and executing JavaScript code, because the implementation principles and optimization strategies of each engine differ. 1. Lexical analysis: convert source code into lexical unit. 2. Grammar analysis: Generate an abstract syntax tree. 3. Optimization and compilation: Generate machine code through the JIT compiler. 4. Execute: Run the machine code. V8 engine optimizes through instant compilation and hidden class, SpiderMonkey uses a type inference system, resulting in different performance performance on the same code.

JavaScript's applications in the real world include server-side programming, mobile application development and Internet of Things control: 1. Server-side programming is realized through Node.js, suitable for high concurrent request processing. 2. Mobile application development is carried out through ReactNative and supports cross-platform deployment. 3. Used for IoT device control through Johnny-Five library, suitable for hardware interaction.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 Linux new version
SublimeText3 Linux latest version

Dreamweaver Mac version
Visual web development tools

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

SublimeText3 Mac version
God-level code editing software (SublimeText3)