I am stuck on a arrays in jQuery. I am returning back from php an array In php file I am adding array like this in a loop:
$table_data[]= array("id"=>mysql_result($query,$i,"id"),"name"=>trim(mysql_result($query,$i,"name")));
at the end of php file :
echo json_encode($table_data);
On my jquery :
$.ajax({
type: "POST",
url: "phpfilename.php",
data: ({
newtask: "grab"
}),
dataType: "json",
success: function(data){
alert("value - "+data.length);
}
});
(this returns correct record counts)
$.each(data, function(key, value) {
alert( "The key is '" + key + "' and the value is '" + value + "'" );
});
(the above loop returns me :
0,1,2 as a key , Object as a value )
I need help with understanidn how to pass arrays from php to jquery and how to handle them . Maybe I am totally on wrong way.
To access any property of an object, the process is:
or
read here