24. Asynchronously loading JSON-formatted data using the Getjson () method

Source: Internet
Author: User

The use getJSON() method can get the array in the server through 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.

For example, click the Load button in the page to invoke the getJSON() method to get data from a JSON-formatted file on the server and iterate through the data to display the specified field name content in the page. As shown in the following:

Effects displayed in the browser:

As you can see, when you click on the "Load" button, the getJSON() method calls the Sport.json file in the server, gets the data returned by the data file, and iterates over the object to data[“name”] fetch the content specified in the data and display it in the page.

24. Asynchronously loading JSON-formatted data using the Getjson () method

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.