это мой PHP код,PHP передача JSON в angularjs
$count=mysql_num_rows($query);
if ($count > 0) {
// output data of each row
$foodList[] = array();
while($row =mysqli_fetch_assoc($result))
{
$foodList[] = $row;
}
} else {}
echo json_encode($foodList);
это мой JS код:
var $promise = $http.post('foodList.php');
$promise.then(function(msg){
var foodList = msg.data;
if (foodList)
{
//$scope.foodList = foodList;
alert(foodList);
}
else
{
//$scope.msg = "Error user name or password";
}
это выход:
$promise.then(function(msg){*msg = Object {data: Array[1], status: 200, config: Object, statusText: "OK"}* var foodList = msg.data;*foodList = [Array[0]]*
Итак: на самом деле 3 в моей базе данных, но на выходе только Array [1]? Как это исправить? THX
изменить '$ foodList [] = массив();' до $ foodList = массив() ; –
выход становится массивом [0] –
var_dump ($ foodList) в вашем php-файле и убедитесь, что ваш php-файл показывает 3 данных –