「jQuery開発」$.each()と$.ajax()を利用するサンプルコード
サンプルコード
$(function(){
$('#send’).click(function(){
$.ajax({
type: “GET",
url: “demo.json",
data: {username:$(“#username").val(), content:$(“#profile").val()},
dataType: “json",
success: function(data){
$('#ctnTxt’).empty(); //ctnTxtのコンテンツをクリア
var html = ";
$.each(data, function(commentIndex, comment){
html += '<div class="comment"><h6>’ +comment['username’]
+ ':</h6><p class="para"' + comment['profile’]
+ '</p></div>’;
});
$('#ctnTxt’).html(html);
}
});
});
});