当我尝试使用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);
Run Code Online (Sandbox Code Playgroud)
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);
});
});
});
});
Run Code Online (Sandbox Code Playgroud)
在 jQuery 的第二行
var id = $('#container').find('.graphic-blank:visible').siblings().attr('id');
Run Code Online (Sandbox Code Playgroud)
您正在尝试访问 jQuery 对象数组(siblings())的 id 属性。$getJSON您需要指定一个 jQuery 对象来获取您的函数的 id
更新如果只有一个同级,请通过以下方式指定:
var id = $('#container').find('.graphic-blank:visible').siblings().eq(0).attr('id');
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1580 次 |
| 最近记录: |