I am using PHP at server side to get json formatted output as below. At client side I use jQuery to display the results but it displays null
. Please let me know where I went wrong. Any help is appreciated.
PHP
while ($r = mysql_fetch_assoc($result))
{
$rows[] = $r;
}
echo json_encode($rows);
Output
[
{
"a_name": "affles",
"bname": "bua",
"c_number": "10101010",
"dateandtime": "2013-11-30 17:50:04"
},
{
"a_name": "affles",
"bname": "bua",
"c_number": "10101010",
"dateandtime": "2013-11-30 17:50:04"
},
{
"a_name": "anan",
"bname": "nesh",
"c_number": "2017439441",
"dateandtime": "2013-12-04 17:50:04"
}
]
Client side
$.getJSON("http://apip.com/results.php", function (data) {
$.each(data, function (index, value) {
$('<li>' + value.a_name + '</li>').appendTo('#groups');
});
});
Client side code using JSONP: I modified client side to use JSONP but still it returns null. An help is appreciatd
<script>
(function() {
var flickerAPI = "http://apip.com/results.php?jsoncallback=?";
$.getJSON( flickerAPI,
(function( data ) {
$.each( data.items, function( index, value ) {
$('<li>' + value.a_name + '</li>').appendTo('#groups');
});
});
})();
</script>