$.getJSON("fetch.php",function(data){ $("ul").empty(); $.each(data.result,function() { $("ul").append("<li>Name : "+this['name']+"</li><br/> "); $("ul").append("<li>Age : "+this['age']+"</li><br/> "); $("ul").append("<li>Company : "+this['company']+"</li><br/> "); }); });
<?php include_once ('db.php'); $sql="Select * from people"; $res= mysql_query($sql); $result=array(); while($row= mysql_fetch_array($res)) { array_push($result, array('name' => $row[0], 'age'=>$row[1], 'company'=>$row[2])); echo json_encode(array("result"=>$result)); } ?>
echo json_encode
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)