Introduction to How to use $.getjson ()

Source: Internet
Author: User

The JSON (JavaScript Object Notation) is a lightweight format for data interchange, which is a JavaScript objects notation. It is very convenient for programmers to deal with the data, but also easy for the machine to parse and generate data, the application is very extensive.

JSON files can be saved as "Test.json" files

The general format of the JSON data is as follows (for an object in "{}", an array in "[]")

{
"Total": 3,
"Rows": [
{
"UserId": 1,
"Realname": "Zhang San",
"Headurl": "Href= ' teadetail.html '",
"img": "Src= ' images/tea1.jpg '",
"Introduction": "Warm and generous." "
},{
"UserId": 2,
"Realname": "Harry",
"Headurl": "Href= ' teadetail.html '",
"img": "Src= ' images/tea2.jpg '",
"Introduction": "Warm and generous." "
},{
"UserId": 3,
"Realname": "John Doe",
"Headurl": "Href= ' teadetail.html '",
"img": "Src= ' images/tea3.jpg '",
"Introduction": "Warm and generous"
}
]
}

The $.getjson () method function in jquery is primarily used to load JSON-encoded data from the server, which uses a get HTTP request.

Here's how to use it:

$.getjson (URL [, data] [, Success (data, Textstatus, JQXHR)])

The URL is a required parameter that represents the address of the JSON data;
Data is an optional parameter that is used to send parameters when data is requested;
Success is a parameter, which is a callback function that is used to process the requested data.

Get JSON data for example:

$.getjson (' Test.json ', function(data) {

for (var i = 0; i < data.rows.length; i++) {

$ (' #test '). Append (' <p> ' + data.rows[i].realname + ' </p> ');

}

});

This article is from the "June Blog" blog, please be sure to keep this source http://liyujun.blog.51cto.com/1482472/1664903

Introduction to How to use $.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.