When i try to display the data with getJSON nothing happens, $('#child-left-container-2')
should display data from the php file. Where did i go wrong?... Below is brief example of my code.
php file
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);
});
});
});
});
I dont't know if this would solve the problem you are experiencing but this would be how I would solve this particular problem. Give this code a try, if it works, stopping sending html thru json would be a bonus.
$key = 0;
while($row = mysql_fetch_assoc($query)) {
//code
$array[$key]['id'] = $id;
$array[$key]['sid'] = $sid;
$array[$key]['user'] = $user;
$array[$key]['content'] = $details1;
$array[$key]['style'] = $style;
$key++;
}
echo json_encode($array);
JS:
$(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
for (var i in data){
var id = data[i].id;
var sid = data[i].sid;
var user = data[i].user;
var content = data[i].content;
var style = data[i].style;
$('#child-left-container-2').append($('<div />').addClass('array-container-2')attr('id', id)
.attr('data-sid', sid).attr('data-user', user).html(content);
}
});
});
});
I confess that not knowing what $style is or how it would appear rendered I couldn't add it to the chain. If you post the content of $style I can update the anwser. I hope this helps.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With