我正在使用angularjs在下面的程序中工作我没有得到任何来自ajax call.i没有得到什么错误在下面的代码

时间:2016-12-23 08:38:16

标签: php angularjs

在下面的代码中,我想打印mock.json文件的值。 我正在使用带有angularjs.in此代码的php  我从ajax调用得到ajax调用位结果是什么(在响应变量是空白的。)我是angularjs的新请告诉我有什么问题。

<!doctype html>
<html lang="en" ng-app="angularTable">

    <script src="lib/angular/angular.js"></script>
    <script src="lib/dirPagination.js"></script>
    <script >
    var app=angular.module('angularTable',[]);
    app.controller('listdata',function($scope,$http) {
        $scope.users=[];
        $http.get("mockJson/mock.json").success(function(responce){
            $scope.users = response;  
        })
        .error(function(data) {
            console.error('Repos error',  data);
        })
    });

    </script>
 <body>
    <div  ng-controller="listdata">
        <table>
            <tr>
                <th>Id</th>
                <th>Name</th>
            </tr>
            <tr ng-repeat="users in users">
                <td>{{users.id }}</td>
                <td>{{users.first_name }}</td>  
            </tr>
        </table>
    </div>
 </body>
</html>


///Json File(mock.json)

[{"id":1,"first_name":"Heather","last_name":"Bell","hobby":"Eating"},
{"id":2,"first_name":"Andrea","last_name":"Dean","hobby":"Gaming"},
{"id":3,"first_name":"Peter","last_name":"Barnes","hobby":"Reading Books"},
{"id":4,"first_name":"Harry","last_name":"Bell","hobby":"Youtubing"},
{"id":5,"first_name":"Deborah","last_name":"Burns","hobby":"Fishing"},
{"id":6,"first_name":"Larry","last_name":"Kim","hobby":"Skipping"},
{"id":7,"first_name":"Jason","last_name":"Wallace","hobby":"Football"},
{"id":8,"first_name":"Carol","last_name":"Williams","hobby":"Baseball"},
{"id":9,"first_name":"Samuel","last_name":"Olson","hobby":"Programming"},
{"id":10,"first_name":"Donna","last_name":"Evans","hobby":"Playing DOTA"},
{"id":11,"first_name":"Lois","last_name":"Butler","hobby":"Gaming"},
{"id":12,"first_name":"Daniel","last_name":"Hill","hobby":"surfing"},
{"id":13,"first_name":"Matthew","last_name":"Torres","hobby":"cycling"},
{"id":14,"first_name":"Jerry","last_name":"Hernandez","hobby":"Music"},
{"id":15,"first_name":"Christopher","last_name":"Carpenter","hobby":"Football"},
{"id":16,"first_name":"Harold","last_name":"West","hobby":"Gaming"},
{"id":17,"first_name":"Carol","last_name":"Hicks","hobby":"Youtubing"},
{"id":18,"first_name":"Bonnie","last_name":"Davis","hobby":"Partying"},
{"id":19,"first_name":"Nancy","last_name":"Banks","hobby":"Photography"},
{"id":20,"first_name":"Walter","last_name":"Freeman","hobby":"Tweeting"},
{"id":21,"first_name":"Louis","last_name":"Gonzales","hobby":"Bloging"},
{"id":22,"first_name":"Jean","last_name":"Watkins","hobby":"Bloging"},
{"id":23,"first_name":"Albert","last_name":"Harris","hobby":"Music"},
{"id":24,"first_name":"Billy","last_name":"Owens","hobby":"Camping"},
{"id":25,"first_name":"Russell","last_name":"Patterson","hobby":"Singing"}]

1 个答案:

答案 0 :(得分:0)

在您的代码中:

$http.get("mockJson/mock.json").success(function(responce){

    $scope.users = response; 
})

该函数的参数为​​响应,而分配给$scope.users的变量为响应