Login. hmtl
<! -- Login.html -->
<! Doctype HTML> Login. js
// Login. jsvar XMLHTTP; function chkuser () {XMLHTTP = NULL; If (window. XMLHttpRequest) {// code for all new browsersxmlhttp = new XMLHttpRequest ();} else if (window. activexobject) {// code for ie5 and ie6xmlhttp = new activexobject ("Microsoft. XMLHTTP ");} If (XMLHTTP! = NULL) {/* // GET request var username = $ ("# username"). Val (); url = "userchk. php? Username = "+ username; XMLHTTP. open ("get", URL, true); XMLHTTP. onreadystatechange = chkuserres; XMLHTTP. send (); * // post sends the request URL = "userchk. PHP "; var DATA =" username = "+ $ (" # username "). val (); XMLHTTP. open ("Post", URL, true); XMLHTTP. setRequestHeader ("Content-Type", "application/X-WWW-form-urlencoded"); XMLHTTP. onreadystatechange = chkuserres; XMLHTTP. send (data);} else {alert ("your browser does not support XMLHTTP or XMLHttpRequest") ;}} function chkuserres () {If (XMLHTTP. readystate = 4) {If (XMLHTTP. status = 200) {/* // returns var res = XMLHTTP in HTML format. responsetext; $ ("# chkres "). text (RES); * // return var xmlres = XMLHTTP when processing XML format. responsexml; var msgs = xmlres. getelementsbytagname ("MSG") [0]; var msgtext = msgs. childnodes [0]. nodevalue; alert (msgtext); * // return var res = XMLHTTP in JSON format. responsetext; var res_obj = eval ("(" + Res + ")"); // convert a string to a JSON object $ ("# chkres "). text (res_obj.msg );}}}
Userchk. php
// Userchk. php <? PHP/* // return the header in HTML format ("Content-Type: text/html; charset = UTF-8"); header ("cache-control: No-Cache "); // $ username = $ _ Get ['username']; // $ username = $ _ post ['username']; if ($ username = "phf ") {echo "User Name unavailable";} else {echo "User Name available";} * // return in XML format. Header ("Content-Type: text/XML; charset = UTF-8"); header ("cache-control: No-Cache "); $ username = $ _ post ['username']; $ res = ""; if ($ username = "phf ") {$ res = "<res> <MSG> the user name is unavailable </MSG> </RES> ";} else {$ res = "<res> <MSG> available user name </MSG> </RES>";} echo $ res; * // return the header in JSON format ("Content-Type: text/html; charset = UTF-8"); header ("cache-control: No-Cache "); $ username = $ _ post ['username']; $ res = ""; if ($ username = "phf") {$ res = '{"MSG ": "The user name is unavailable "}' ;} Else {$ res = '{"MSG": "username available"}';} echo $ res;?>