Jquery.getjson (URL, [data], [Callback (data, Textstatus)]) returns:xmlhttprequest
Urla string containing the URL to which the request is sent.
Dataa map or string is sent to the server with the request.
Callback (data, textstatus) a callback function that is executed if the request succeeds
$.ajax ({
Url:url,
DataType: ' JSON ',
Data:data,
Success:callback
});
The callback is by returning the data, which will be a Web page effect object or the array defines the structure and parsing of JSON using $. Parsejson () method.
Most implementations will specify a successful handler:
$.getjson (' Ajax/test.json ', function (data) {
$ ('. Result '). html (' <p> ' + data.foo + ' </p> ')
+ ' <p> ' + data.baz[1] + ' </p> ');
});
This example, of course, relies on the structure of the JSON on the file:
{
"foo": "The quick brown fox jumps tutorial over the lazy dog."
"Bar": "ABCDEFG",
"Baz": [52, 97]
}
Use this structure, such as inserting the first string, from the second to the number of paging files.
It's important: in jquery 1.4, if the file contains a JSON syntax error, the request usually fails to prompt. Avoid the frequent hand-edited JSON data for this reason. JSON is a data interchange format that is more restrictive than the text symbols of JavaScript objects. For example, all representations in the JSON string, whether property or value, must be enclosed in double quotes. See http://json.org/for details about the JSON format.
Jsonp
If the URL contains a string "callback =?" "In the URL, the request is treated as JSONP instead." See JSONP data type for discussion, $. Ajax () for more details.
Additional considerations:
Due to browser security restrictions, most "Ajax" requirements are based on the same source policy; Requests cannot be successfully retrieved from different domains, subdomains, or protocol data.
Scripts and JSONP requests are not subject to the same restrictions on the origins of the policy
<!doctype html>
<style>img{height:100px; float:left;} </style>
<script src= "Http://code.jquery.com/jquery-latest.min.js" ></script>
<body>
<div id= "Images" >
</div>
<script>$.getjson ("http://api.flickr.com/services/feeds/photos_public.gne?tags=cat&tagmode=any& Format=json&jsoncallback=? ",
function (data) {
$.each (Data.items, function (I,item) {
$ ("if (i = = 3) return false;
});
});</script>
</body>