Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 在angularjs中处理json响应(来自PHP和mysql)_Javascript_Php_Mysql_Angularjs_Json - Fatal编程技术网

Javascript 在angularjs中处理json响应(来自PHP和mysql)

Javascript 在angularjs中处理json响应(来自PHP和mysql),javascript,php,mysql,angularjs,json,Javascript,Php,Mysql,Angularjs,Json,在隐藏来自php的Json响应时遇到麻烦。我使用AngularJs显示接收到的Json数据。我是个新手,刚开始时尝试了一个简单的练习。请帮忙。提前谢谢 index.html 使用AngularJS的PHP MySQL API 域名城市 {{user.user_id}{{user.first_name}{{user.user_city}} var-app=angular.module('app',[]); app.controller('GetUsers',函数($scope,$http){ $

在隐藏来自php的Json响应时遇到麻烦。我使用AngularJs显示接收到的Json数据。我是个新手,刚开始时尝试了一个简单的练习。请帮忙。提前谢谢

index.html


使用AngularJS的PHP MySQL API
域名城市
{{user.user_id}{{user.first_name}{{user.user_city}}
var-app=angular.module('app',[]);
app.controller('GetUsers',函数($scope,$http){
$http.get('http://localhost/angmysql/api.php)。成功(函数(数据){
$scope.users=数据;
});
}
});
api.php


由$http传递到回调的参数是一个对象,响应主体存储在.data字段中

试试这个:

$http.get('http://localhost/angmysql/api.php').success(function(response) {
    $scope.users = response.data;
}); 


有什么问题吗?http promise上的success函数中包含哪些数据变量?您可以像
$http.get('http://localhost/angmysql/api.php)。然后(函数(响应){console.log(响应)})
response.data
中查看您的响应和您的
用户的响应。在这种情况下,我认为返回的结果与您的想法不同。尝试将其记录到控制台<代码>控制台.日志(响应.数据)
你得到了什么?需要更多信息,否则这只是猜测。
<?php

    $db_name  = 'dbtuts';
    $hostname = 'localhost';
    $username = 'root';
    $password = '';

    $dbc = mysqli_connect('localhost','root','','dbtuts') or die('Error connecting to database');

    $sql = mysqli_query($dbc,"SELECT * FROM users");

    $emparray = array();

    while($row =mysqli_fetch_assoc($sql))
    {
        $emparray[] = $row;
    }

    echo json_encode($emparray);

    mysqli_close($dbc);
?>
$http.get('http://localhost/angmysql/api.php').success(function(response) {
    $scope.users = response.data;
}); 
The response object has these properties:

data – {string|Object} – The response body transformed with the transform functions.
status – {number} – HTTP status code of the response.
headers – {function([headerName])} – Header getter function.
config – {Object} – The configuration object that was used to generate the request.
statusText – {string} – HTTP status text of the response.