php - how to display or append json data from js to html -
how can display json data js html
here code have tried
<script> $.ajax({ url:'load_categories.php', type:'get', data:{'from':loaded,'to':loadmore}, success: function (res) { var categories = $.parsejson(res); var i=0; (var x in categories){ alert(categories.date_+i); $('#categories').append('<div>'+(categories.date_+i+'</div>'); //not displaying on html i++; } $('#loadmore').attr('num_loaded',(loaded+10)); } }); </script> <div id="categories"></div> <?php //load_categories.php $res = mysql_query("select * impressions limit $from,$to"); //echo "select * impressions limit $from,$to"; $arr = array(); $i= 0; while($row = mysql_fetch_array($res)) { $arr['rec_id_'.$i] = $row['rec_id']; $arr['date_'.$i] = $row['date']; $i++; } echo json_encode($arr);
where im doing wrong...
i think wrong categories.date_+i, how can add 0,1,2,...
i've fixed code please 5 try
the correct code :
<script> $.ajax({ url:'load_categories.php', type:'get', data:{'from':loaded,'to':loadmore}, success: function (res) { var categories = $.parsejson(res); for(var i=0;i< categories.length;i++) { var row = categories[i]; alert(row.date); $('#categories').append('<div>'+row.date+'</div>'); //not displaying on html } $('#loadmore').attr('num_loaded',(loaded+10)); } }); </script> <div id="categories"></div> <?php //load_categories.php $res = mysql_query("select * impressions limit $from,$to"); //echo "select * impressions limit $from,$to"; $arr = array(); while($row = mysql_fetch_array($res)) { $arr[] = row; } echo json_encode($arr);
Comments
Post a Comment