dpy3846 2016-12-23 08:38
浏览 48
已采纳

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

In below code i want to print the values of mock.json file. I am using the php with angularjs.in this code i gave the ajax call bit result from ajax call is nothing (in responce variable is blank).i am new with angularjs please tell me what is wrong.

<!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条回答 默认 最新

  • doujiepin5547 2016-12-23 08:51
    关注

    In your code:

    $http.get("mockJson/mock.json").success(function(responce){
    
        $scope.users = response; 
    })
    

    the argument to the function is responce while the variable that is assigned to $scope.users is response.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器