JSON file
{' A '
: [
{' id ': ' 1 "," Sex ":" Male "},
{" id ":" 2 "," Sex ":" Male "},
{" id ":" 3 "," Sex ":" Male "},
{" id ":" 4 "," Sex ":" Female "}
]
}
Js
Method One:
$.ajax ({
URL: "Ceshi.json",//json file location
type: "Get",//Request mode is get
dataType: "JSON",//Return Data format to JSON
Success:function (data) {///the method to be executed after the successful completion of the request
//each Loop uses the $.each method to traverse the returned data date
$.each (Data.first, function (i), Item) {
var str = ' <div>id: ' + item.name + ' sex: ' + item.sex + ' </div> ';
document.write (str);
})
}
Method Two:
Jquery.getjson () is a shorthand form of the Jquery.ajax () function.
//jquery.getjson (URL [, data] [, success])
$.getjson ("Ceshi.json", "", Function (DA TA) {//each loops use the $.each method to traverse the returned data date $.each (Data.first, function (I, item) {var str = ' <DIV&G
t; Name: ' + item.name + ' sex: ' + item.sex + ' </div> ';
document.write (str); })
});