我对如何从 jquery 中的 json 数组中检索所有值有点困惑。我知道它需要循环但如何?功能 - 目前是:
$.ajax({
url: 'query.php',
data: "",
dataType: 'json',
success: ajaxfunction
});
function ajaxfunction(json_data){
// problem is below, i need to output all the data from the array
console.log (json_data)
while(json_data){
$('#maindisplay').html("<b>Product: </b>"+json_data.prod_name+"<b> colour: </b>"+json_data.colour); // problem is here, i need to output all the data from the array
}
}
php:
$result = mysql_query("SELECT * FROM fproduct WHERE fproduct.category='Shirts'");
$elements = array ();
do{
$row=mysql_fetch_array($result);
if ($row) //if there is anything
$elements[] = ($row);
} while($row);
echo json_encode($elements);