Skip to content Skip to sidebar Skip to footer

How To Make Jquery Objects Of Array From Php Response Of Ajax Call

Here is my javascript variable my, i wanted to get it from php file. Inside the selectAnnotation.php i am just echoing it echo '{ src : 'http://192.168.1.58/annotate/drive/ima

Solution 1:

Try constructing like this:

$Result = $Connection->query($Query); 
$result=array(); 
$i=0; 
while($row = $Result->fetch_assoc()){ 
$result[$i]['src']=$row['src']; 
$result[$i]['text']=$row['text']; 

$result[$i]['shapes'][]=array('type'=>'rect','geometry'=>array('x' => $row['x'], 'y'=> $row['y'], 'width' => $row['width'], 'height'=>$row['height']) ); 
$i++; 
} 
echo json_encode($result);

//javascript response after success...

data=JSON.parse(data); 
for(var i=0;i<data.length;i++){ 
console.log(data[i]); 
}

Solution 2:

try to use json_encode and json_decode to transfer your data. In js JSON.parse

Solution 3:

Its my first answer on SO.

I guess the correct way to do it would be to use eval(). However it is rather recommended to use json_encode and json_decode as Ninjava has suggested.

Post a Comment for "How To Make Jquery Objects Of Array From Php Response Of Ajax Call"