$.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);
    }
});

 

 

 

posted @ 2017-05-31 14:29  念念念不忘  阅读(723)  评论(0)    收藏  举报