【发布时间】:2012-01-19 22:18:37
【问题描述】:
当我尝试使用 getJSON 显示数据时,没有任何反应,$('#child-left-container-2') 应该显示来自 php 文件的数据。我哪里出错了?...下面是我的代码的简短示例。
php 文件
while($row = mysql_fetch_assoc($query)) {
//code
$array[] = "<div class='array-container-2' $style id='$id' data-sid='$sid' data-user='$user'>$details1</div>";
}
echo json_encode($array);
jquery
$(function() {
$('.next_button').click(function() {
var id = $('#container').find('.graphic-blank:visible').siblings().attr('id');
$.getJSON('fetchstack.php?id='+id,function(data) {
$('#child-left-container-2').html(''); //clear div
$.each(data,function(i,result) {
$('#child-left-container-2').append(result);
});
});
});
});
【问题讨论】:
-
在
data对象上尝试console.log()看看是 dom 插入还是 json get 有问题 -
检查萤火虫控制台的错误...
-
这意味着您的 PHP 脚本中有错误,并且您没有收到 JSON 响应。