PHP Processing Ajax

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.