美文网首页
jquery 的ajax小案例

jquery 的ajax小案例

作者: 阿泽453 | 来源:发表于2017-12-14 17:00 被阅读0次
案例代码:

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

相关文章

网友评论

      本文标题:jquery 的ajax小案例

      本文链接:https://www.haomeiwen.com/subject/ipgkwxtx.html