Install Wamp First, if the installation of MySQL terminates the process to prevent conflicts, you can access the localhost instructions successfully. Create a new project under the WWW directory and use localhost to access it.
Php:
<?PHP//3. Get AJAX-passed content processing Header("Content-type:text/text;charset=utf-8"); $username=$_post[' Name ']; if($username= = ' Admin '){ Echo' {' inf ': ' The user name is not valid ', ' STA ': ' 0 '} '; } Else if($username= = ' Malin '){ Echo' {' inf ': ' The user name has been registered ', ' sta ': ' 1 '} '; } Else{ Echo' {' inf ': ' The user name can be registered ', ' sta ': ' 2 '} '; } ?>
<!DOCTYPE HTML><HTML> <Head> <MetaCharSet= "UTF-8"> <title></title> <styletype= "Text/css">. Green{Color:Green; }. Red{Color:Red; } </style> <Script>window.onload=function(){ functionID (ID) {returndocument.getElementById (ID); } functionAjax () {varOajax=NewXMLHttpRequest (); returnOajax; } ID ('username'). onkeyup=function(){ //1 building an AJAX engine varXHR=Ajax (); //3 PHP Back-end operations varURL='/m18ajaxt/checknamejson.php?name='+ID ('username'). Value; Xhr.open ('POST', URLs,true); Xhr.setrequestheader ("Content-type","application/x-www-form-urlencoded"); varData="name="+ID ('username'). Value; //2 send request, get with NULL, because sent by URLxhr.send (data); Xhr.onreadystatechange=function(){ if(Xhr.readystate==4 &&Xhr.status== $){ //4 rendering the DOM varInformation=Json.parse (xhr.responsetext). inf; varSTA=Json.parse (xhr.responsetext). STA; ID ('inf'). InnerHTML=information; if(STA==0) {ID ('inf'). ClassName="Red"; }Else if(STA==1) {ID ('inf'). ClassName="Red"; }Else{ID ('inf'). ClassName="Green"; } } } } } </Script> </Head> <Body> <formAction=""Method= "Get">Username:<inputtype= "text"ID= "username" /> <inputtype= "button"name= "BTN"ID= "BTN"value= "Verify" /> </form> <spanID= "INF">This is infomation</span> </Body></HTML>
PHP Processing Ajax