Get the App
SLTechnology News&Howtos  ›  Development  › 

How to use Ajax Technology to detect user name in php

Shulou Source: shulou.com Published: 2022-06-03 04:06:18 10月17日 Update

This article mainly introduces php how to use Ajax technology to detect user name, the article is very detailed, has a certain reference value, interested friends must read it!

1. Build the Ajax development framework with the following code

Var http_request = false;function createRequest (url) {/ / initialize the object and issue a XMLHttpRequest request http_request = false; if (window.XMLHttpRequest) {/ / Mozilla and other browsers http_request = new XMLHttpRequest (); if (http_request.overrideMimeType) {http_request.overrideMimeType ("text/xml") }} else if (window.ActiveXObject) {/ / IE browser try {http_request = new ActiveXObject ("Msxml2.XMLHTTP");} catch (e) {try {http_request = new ActiveXObject ("Microsoft.XMLHTTP") } catch (e) {}} if (! http_request) {alert ("cannot create XMLHTTP instance!"); return false;} http_request.onreadystatechange = alertContents / / specify response method http_request.open ("GET", url, true); / / issue HTTP request http_request.send (null) } function alertContents () {/ / process the information returned by the server if (http_request.readyState = = 4) {if (http_request.status = = 200) {alert (http_request.responseText);} else {alert ('error found on the page you requested');}

two。 Write the custom function checkname () of JavaScript to detect whether the user name is empty. If the user name is not empty, call the createRequest () method to send a request to detect the existence of the user name. The code is as follows:

Function checkname () {var username= form1.user.value; if (username== ") {window.alert (" Please enter a user name ");} else {createRequest ('action/checkname.php?username='+username+'&nocache='+new Date (). GetTime ());}}

3. Add "detect user name hyperlink" to the page

Tags: User name detection code page technology application content method browser article processing browsing value information interest function instance object guy Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Shulou Information Shulou Tech Info Microsoft Redmi Shulou Technology