Home  >  Article  >  Web Front-end  >  Sample code for reading json files in jQuery_jquery

Sample code for reading json files in jQuery_jquery

WBOY
WBOYOriginal
2016-05-16 17:34:081238browse

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











Statement:
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