Home > Web Front-end > JS Tutorial > body text

Sample code for reading json files in jQuery_jquery

WBOY
Release: 2016-05-16 17:34:08
Original
1241 people have browsed it

The json file is a lightweight data interaction format. Generally, it is read using the getJSON() method in jquery.

Copy code The code is as follows:

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

url: loaded page address
data: optional, data sent to the server, in the format of key/value
callback: optional, callback executed after successful loading Function
1. First create a JSON format file userinfo.json to save user information. As follows:
Copy code 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 Jie",
" sex":"female",
"email":"zhenjie@123.com"
}
]

2. Secondly, create a page to obtain the JSON file User information data and display
Copy code The code is as follows:





getJSON to get data











Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template