Jqueryを使用して、データベースから取得したアイテムをWebページに表示しようとしています。しかし、私のコードはそれを行うことができませんでした。配列からアイテムを表示する方法を教えてください。
私のコードは次のとおりです。
success: function( data, textStatus, jqXHR)
{
if(data.success)
{
for(var i = 0,len=data.length;i<len;i += 1){
if(data.commentInfo[i].success)
{
var newcommhtml = '<div id="c0'+thecid+'" class="cnew clearfix"> <section class="c-author">';
newcommhtml = newcommhtml + '<h3>Anonymous</h3>';
newcommhtml = newcommhtml + '<span class="pubdate">'+month+' '+day+', '+year+'</span> </section>';
newcommhtml = newcommhtml + '<section class="c-content">';
newcommhtml = newcommhtml + '<img src="images/green-avatar.png" alt="avatar" width="80" height="80" class="ava">';
newcommhtml = newcommhtml + '<p>'+nl2br(data.commentInfo[i].comment)+'</p> </section></div>';
var thelm = "#c0"+thecid;
commwrap.append(newcommhtml);
$(thelm).hide().fadeIn('slow');
setTimeout(function() { $(thelm).addClass('green'); }, 800);
$("#comm").val("");
thecid++;
}
else
{
alert("dsdsds");
}
}
if(errorspan.html() != null) {
errorspan.remove();
}
}
},
error: function(jqXHR, textStatus, errorThrown)
{
alert("error"+errorThrown);
console.log("Something really bad happened " + textStatus);
},
サーバーから受信した応答は次のとおりです。
{"success":true,"commentInfo":[{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"},{"uname":"shyam","comment":"ghg"}]}
誰か助けてください....ありがとう....