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 stm32开发clion时遇到的编译问题
  • ¥15 lna设计 源简并电感型共源放大器
  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程