Using jquery for easy access to Ajax asynchronous data, the following example is an AJAX feature similar to the type user name
jquery.post (URL, [data], [callback], [type]): asynchronous request using POST method
Parameters:
URL (String): The URL address where the request is sent.
Data (MAP): (optional) The information to be sent to the server, expressed as a Key/value key-value pair.
Callback (function): (optional) the callback function (which is invoked only if the response return state is success) when loading succeeds.
Type (String): (optional) The official description is: type of data to is sent. The type that should actually be requested for the client (Json,xml, etc.)
This is a simple POST request function to replace the complex $.ajax. Callback functions can be invoked when the request succeeds. If you need to perform a function when an error occurs, use $.ajax. Sample code:
JS Code
| code is as follows |
copy code |
|
<script
$ (document). Ready (function () {
$ (". Ajax_btn"). Click (function () {
$.post ("ajax.php",//Asynchronous Processing dynamic page
{name: $ (". Name"). Val ()},//get the class named " The value of name literal, the value of
function (data) {//data to return value, function to reverse value,
$ (". Content"). val (data); When you get a return value, fill it in a text box with the class name "content"
});
})
})
</script> |
ajax.php Code
| The code is as follows |
Copy Code |
|
<?php
$name =$_post["name"];
if ($name = = "Netxu") {
echo "I'm sorry," $name. " Data exists ";
}
else{
echo "Congratulations," $name. " can use ";
}
?> |
HTML code
| The code is as follows |
Copy Code |
|
<p> page effect is as follows: (When you enter <a href= "http://www.111cn.net" title= "Thoughts" >netxu</a>, will prompt the data to exist, you enter other then prompt data available) < /p>
<p> value text: <input type= "text" class= "name" size= "" value= "Netxu"/></p>
<p> Asynchronous Reception: <input type= "text" class= "content" size= "style=" color: #F00 "/> <input type=" button "class=" Ajax_btn "value=" Asynchronous processing/></p> |
On the other hand, ASP is the same, but the output form is different