In my php file I have
$data = array();
while ($row = mysql_fetch_array($result, true))
{$data[] = $row;};
echo json_encode($data);
It produces the JSON array:
[
{
"record_id": "4",
"eq_type_id": "999",
"scidiv_id_tag": "AKINS04",
"date_last_updated": "2011-07-11 14:41:58",
"description": "Optics Table D",
"eq_type_desc": "Other Equipment Type"
}
]
In my JQUERY script:
$.ajax(
{
type: "GET",
//dataType: "json",
url: "../scidiv/php/editData.php",
data: "recid=" + scidivtag,
success: function(data)
{
$('#output1').html(data);
$('#output').html("<b>id: </b>"+ data[0].record_id + "<b> name: </b>" +data[1].eq_type_id);
}
});
$('#output1').html(data); displays the above array on my web page....
But both
$('#output').html("Record Id: "+ data.record_id+"Eq Type ID: "+ data.eq_type_id);
an
$('#output').html("Record Id: "+ data[0].record_id+"Eq Type ID: "+ data[1].eq_type_id);
Gives me
id: undefined name: undefined
Can someone tell me what I’m missing??
Thanks
Chris
Thanks for all the assistance and suggestions…
I solved the problem by re-writing my php script from scratch…
The main thing I did was get the results of the query as a simple array since I’m getting only one row of data the query:
So my json looks like:
Thanks again!!