Reputation:
this is my code on server side
$results = array();
while($rw = $objS->row($rs))
{
$results[]=array('id'=>$rw["id"],
'agent_id'=>$rw["agent_id"],
'agent'=>$rw["agent"]);
}
echo json_encode($results);
on client side i have this coding
success: function( data ) {
var forum = data.results;
for(i = 0, l = forum.length; i < l; i++) {
row = forum[i];
alert(row.id);
}
how to develop json on server side? my json returns is
[{"id":"1","agent_id":"1","agent":"Rustomadmin"}]
i need like this
{"results":[{"id":1,"agent_id":"888","agent":"Emili"}]}
Upvotes: -1
Views: 62
Reputation: 2819
Your array()
declaration is totally wrong.. Try this..
To populate multiple record values means,
<?php
while($rw = $objS->row($rs))
{
$results[] = $rw; // It generate Array of Array
}
$agentResult['results'] = $results;
$jsonResult = json_encode($agentResult);
echo $jsonResult;
?>
Upvotes: 1