The use getJSON() method can get the array in the server through the way of Ajax asynchronous request, and parse the obtained data, which is displayed in the page, it is called in the following format:
jQuery.getJSON(url,[data],[callback])Or$.getJSON(url,[data],[callback])
Where the URL parameter is the server address for the request to load the JSON-formatted file, the option data parameter is the one that is sent when the request is requested, and the callback parameter is the callback function that executes after the data request succeeds.
For example, click the Load button in the page to invoke the getJSON() method to get data from a JSON-formatted file on the server and iterate through the data to display the specified field name content in the page. As shown in the following:
Effects displayed in the browser:
As you can see, when you click on the "Load" button, the getJSON() method calls the Sport.json file in the server, gets the data returned by the data file, and iterates over the object to data[“name”] fetch the content specified in the data and display it in the page.
24. Asynchronously loading JSON-formatted data using the Getjson () method