Let's get started with jquery in the last chapter. Example 2 User Registration (Simple Form Verification) (http://www.cnjquery.com/html/JQueryjiaocheng/200807/17-519.html)
There is a line of statements in it
$. Get ("php/user_register.php", {act: $ (this ). attr ("ID"), v: $ (this ). val ()}, function (txt ){
Msg.html (txt );
})
This is a simple example of jquery ajax applications.
What Is ajax?
AJAX is called "Asynchronous JavaScript and XML" (Asynchronous JavaScript and XML). It is a Web page development technology used to create interactive web applications.
If you are not very clear please refer to http://baike.baidu.com/view/1641.htm
Let's take a look at jquery's support for ajax.
First, let's talk about $. get.
$. Get (url, params, callback)
Request to mount a remote page using GET
Returned value: XMLHttpRequest
Parameters:
- Url (String): the URL address of the loaded page.
- Params (Map): (optional) Key/value pair parameter sent to the server.
- Callback (Function): (optional) Function executed when the remote page is loaded.
Instance:
For example, the demo1 html code is as follows:
<A href = "javascript: void (0)"> demo </a>
<Div ID = "show" style = "border: solid 1px # FF6600"> added content: </div>
The get.html code is as follows:
<Strong> ajax get content </strong>
Now I want to click the demo to load the get.html content to the div.
<Script language = "JavaScript">
<! --
$ ("Document"). ready (function (){
$ ("A"). click (function () {// bind a click event to the div
$. Get ("get.html", function (data ){
$ ("# Show" ).html ($ ("# show" ).html () + "<br>" + data );
})
})
})
// -->
</SCRIPT>
If you want to include parameters, you only need
$. Get ("get.html", {parameter name 1: "parameter 1 value", parameter name 2: "parameter 2 value"}, function (data ){
$ ("# Show" ).html (data );
})
$. Post (url, params, callback)
Mount a remote page using HTTP POST
Returned value: XMLHttpRequest
Parameters:
- Url (String): the URL address of the loaded page.
- Params (Map): (optional) Key/value pair parameter sent to the server.
- Callback (Function): (optional) Function executed when data loading is complete.
For the $. post demo, I will not write it. It is exactly the same as $. get. It is only a get request and a post request.