[JQuery tutorial] jquery getting started instance tutorial 3 ajax application

Source: Internet
Author: User

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.


Click to download

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.