Recieve (asks for data and interprets data)
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
$.ajax({ url: "getitems.php", dataType: "json", type: 'GET', data: "imagetosearch="+thetext, //variable with data success: function(data){ alert(data[0].item1), alert(data[0].item2), alert(data[0].item3), alert(data[0].item4), alert(data[0].item5), alert(data[0].item6), alert(data[0].item7), alert(data[0].item8) } }); |
Send (Creates Json Array)
[{“item1″:”Egg”,”item2″:”Celery”,”item3″:””,”item4″:””,”item5″:””,”item6″:””,”item7″:””,”item8″:””}]
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
$query=mysql_query("SELECT * FROM user_uploads where image_name = '$my_data'"); $json=array(); while($student=mysql_fetch_array($query)){ $json[]=array( 'item1'=> $student["item1"], 'item2'=> $student["item2"], 'item3'=> $student["item3"], 'item4'=> $student["item4"], 'item5'=> $student["item5"], 'item6'=> $student["item6"], 'item7'=> $student["item7"], 'item8'=> $student["item8"] ); } echo json_encode($json); |