Possible Duplicate:
I have a nested data structure / JSON, how can I access a specific value?
i have a javascript which does a XMLHttp request to a php file, which in turn queries a mysql table and returns a JSON array... but somehow i cannot access individual elements of the array. here is the javascript:
<script type="text/javascript">
function show(){
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
}
xmlhttp.onreadystatechange= function () {
if(xmlhttp.readyState==4 && xmlhttp.status==200){
var response= new Array();
response=xmlhttp.response;
alert(response);
}
}
xmlhttp.open('GET','test.php', true);
xmlhttp.send();
}
</script>
and this is the php script:
mysql_select_db('testpolaroid') or die ('Unable to select database!');
$query = 'SELECT * FROM images';
$result = mysql_query($query) or die ('Error in query: $query. ' . mysql_error());
if(mysql_num_rows($result) > 0)
{
$row = mysql_fetch_assoc($result);
echo json_encode($json);
}
the response that i get is :
{"imageid":"11","location":"11.jpg"}