1.load () method
The load() method uses the AJAX request to load the data from the server and puts the returned data into the specified element, which is called in the following format:
load(url,[data],[callback])
The parameter URL is the load server address, and optionally the data parameter is the callback function that is sent when the data request is requested, and the callback parameter is the execution of the database.
Disadvantage: The obtained content must be inserted into the page before processing. Execution is inefficient.
2.getJSON
Get the data through the global function and traverse the data display.
The getJSON() method can get the data in the server by 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.
$ ("#btnShow"). Bind ("click", Function () { var $this = $ (this); $.getjson ("Http://www.imooc.com/data/sport.json", function (data) { $this. attr ("Disabled", "true"); $.each (data, function (index,sport) { //index,json) subscript. The value of the underlying sport. if (index==2) $ ("ul"). Append ("<li>" + sport["name"] + "</li>");}) })
3.
Basic Ajax Learning