$.getJSON() —— 加载 json 文件
描述:加载 json 文件,获取数据,也支持jsonp的形式
写法:$.getJSON("地址",function(date){})
参数:
回调函数:载入成功后运行,处理返回的数据
date:json返回的数据
$.ajax写法:
$.ajax({ type: "GET", url: "test.json", dataType: "json", success: function (data) { $('#resText').empty(); var html = ''; $.each(data, function (commentIndex, comment) { html += '<div class="comment"><h6>' + comment['username'] + ':</h6><p class="para">' + comment['content'] + '</p></div>'; }) $('#resText').html(html); } });