Sample Code for reading a json file in jQuery _ jquery

Source: Internet
Author: User
Json file is a lightweight data interaction format. The getJSON () method is generally used in jquery to read data. The sample code is as follows. For more information, see, it is expected that your json file is a lightweight data interaction format. GetJSON () is generally used in jquery to read data.

The Code is as follows:


$. GetJSON (url, [data], [callback])


Url: the address of the loaded page.
Data: Optional. data sent to the server. The format is key/value.
Callback: Optional. callback Function executed after successful Loading
1. Create a JSON Format File userinfo. json to save user information. As follows:

The Code is as follows:


[
{
"Name": "Zhang Guoli ",
"Sex": "male ",
"Email": "zhangguoli@123.com"
},
{
"Name": "Zhang tielin ",
"Sex": "male ",
"Email": "zhangtieli@123.com"
},
{
"Name": "Deng Yi ",
"Sex": "female ",
"Email": "zhenjie@123.com"
}
]


2. Create a page to obtain the user information data in the JSON file and display

The Code is as follows:






GetJSON

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.