在jQuery中我们可以使用jQuery.getJSON()方法很方便的异步从后台获取json格式的数据。(当然也可以使用jQuery.get(),jQuery.post(),jQuery.ajax()方法返回json格式数据,)
下面引用的是官方API对$.getJSON()的说明:
jQuery.getJSON( url, [data,] [success(data, textStatus, jqXHR)] )
urlA string containing the URL to which the request is sent.
dataA map or string that is sent to the server with the request.
success(data, textStatus, jqXHR)A callback function that is executed if the request succeeds.
回调函数中接受三个参数,第一个书返回的数据,第二个是状态,第三个是jQuery的XMLHttpRequest,后面俩个参数可以省略,一般我们只使用到第一个参数,即返回值。
JQuery中使用方法是$.each()来遍历json对象:关于$.each()的详细介绍可以