Basic Ajax Learning

Source: Internet
Author: User

1.load () method

The load() method uses the AJAX request to load the data from the server and puts the returned data into the specified element, which is called in the following format:

 load(url,[data],[callback])

The parameter URL is the load server address, and optionally the data parameter is the callback function that is sent when the data request is requested, and the callback parameter is the execution of the database.

Disadvantage: The obtained content must be inserted into the page before processing. Execution is inefficient.

2.getJSON

Get the data through the global function and traverse the data display.

The getJSON() method can get the data in the server by the way of Ajax asynchronous request, and parse the obtained data, which is displayed in the page, it is called in the following format:

 jQuery.getJSON(url,[data],[callback])Or$.getJSON(url,[data],[callback])

Where the URL parameter is the server address for the request to load the JSON-formatted file, the option data parameter is the one that is sent when the request is requested, and the callback parameter is the callback function that executes after the data request succeeds.

     $ ("#btnShow"). Bind ("click", Function () {                var $this = $ (this);                $.getjson ("Http://www.imooc.com/data/sport.json", function (data) {                        $this. attr ("Disabled", "true");                        $.each (data, function (index,sport) {                        //index,json) subscript. The value of the underlying sport.                            if (index==2)                            $ ("ul"). Append ("<li>" + sport["name"] + "</li>");})     })

3.

Basic Ajax Learning

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.