Ajax jquery asynchronous Form Verification sample code

Source: Internet
Author: User

File directory:
 
Html code:
Copy codeThe Code is as follows:
<Html>
<Head>
<Title> asynchronous Form Verification </title>
<Script type = 'text/javascript 'src = 'jquery. js'> </script>
<Script>
Function checkname (){
// $ ("Input [name = 'name']"). val ()
$. Ajax ({
Type: "get ",
Url: 'index. php ',
Data: "name =" + $ ("input [name = 'name']"). val (),
Success: function (msg ){
$ ("# Show"). append (msg );
}
});

}
</Script>
</Head>
<Body>
<Form name = 'form'>
<Input name = 'name' type = 'text' onblur = 'checkname (); '>
<Span id = 'show'> </span> <br/>
<Input type = 'submit 'name = 'submit' value = 'Submit'/>
</Form>
</Body>
</Html>

Php code:
Copy codeThe Code is as follows:
<? Php
// Connect to the server
$ Link = mysql_connect ('localhost', 'root', 'sanyun ');
If (! $ Link ){
Die ('Connection failed: '. mysql_error ());
}
// Connect to the database
Mysql_select_db ('expur', $ link );

// $ Name = $ _ GET ['name'];
Echo $ name;
$ SQL = "select name from user_info where name = '$ name '";

// Execute the query statement
$ Result = mysql_query ($ SQL );


If (mysql_num_rows ($ result )! = 0 ){
Echo "<font color = 'red'> the name is too popular. Change it. </font> ";
} Else {
Echo "<font color = 'blue'> success </font> ";
}

// Release the query result set
Mysql_free_result ($ result );
// Close the database connection
Mysql_close ($ link );
?>

Running result example:

Related Article

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.