感謝您的期待PHP和JSON評論幫助
我的問題是,我似乎無法讓jquery顯示我生成的數據。
這裏是我的JSON輸出
("posts":[{"id":"1-2","time":"0","name":"dash","avatar":"http:\/\/www.gravatar.com\/avatar\/9ff30cc2646099e31a4ee4c0376091b0?s=182&d=identicon&r=PG","comment":"rtetretrete tet rt uh utert"},{"id":"2-2","time":"0","name":"james","avatar":"http:\/\/www.gravatar.com\/avatar\/d41d8cd98f00b204e9800998ecf8427e?s=182&d=identicon&r=PG","comment":"fsdfdfsdf\r\n"}])
這裏是我的jQuery
$(document).ready(function(){
var url="comments.php";
$.getJSON(url,function(json){
$.each(json.posts,function(i,post){
$("#content").append(
'<div class="post">'+
'<h1>'+post.name+'</h1>'+
'<p>'+post.comment+'</p>'+
'<p>added: <em>'+post.time+'</em></p>'+
'<p>posted by: <strong>'+post.name+'</strong></p>'+
'<p>avatar: <strong>'+post.avatar+'</strong></p>'+
'</div>'
); });
});
});
這是什麼都用PHP做什麼? – 2010-06-16 08:22:25
json是由php生成的。實際問題與此無關,但涉及到。 – 2010-06-17 12:24:43