jquery 的ajax小案例

2017-12-14  本文已影响0人  阿泽453
案例代码:

$(function(){
    $('#send').click(function(){
        $.ajax({
            type: "GET",
            url: "test.json",
            data: {username:$("#username").val(), content:$("#content").val()},
            dataType: "json",
            success: function(data){
                $('#resText').empty();   //清空resText里面的所有内容
                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);
            }
         });
    });
});

上一篇 下一篇

猜你喜欢

热点阅读