weixin_33695082 2014-08-27 11:54 采纳率: 0%
浏览 4

角$ http得到

I want to make an ajax call in angularJS, JSON is loading but the data is not populating.

    demoApp.controller('MainController', function($scope, GetData) {

        $scope.data = null;
        GetData.getDoctors(function(dataResponse) {
            $scope.data = dataResponse;
        });

    });


    demoApp.factory('GetData', function($http) {

        var doctors = [];
        this.getDoctors = function(callBack) {
            $http({

                method: 'GET',
                url: 'json/location.json'
            }).
            success(function(data) {
                callBack(data);
            }).
            error(function(data) {
                alert("Error");
            });

        }
    });

Even the Json file is not loading ..what is the error in the code?

  • 写回答

1条回答 默认 最新

  • weixin_33725722 2014-08-27 13:40
    关注

    Angular factory should return something.

    Try

    demoApp.factory('GetData', function($http) {
        var methods = {};
    
        methods.getDoctors = function(callBack) {
            $http({
                method: 'GET',
                url: 'json/location.json'
            }).
            success(function(data) {
                callBack(data);
            }).
            error(function(data) {
                alert("Error");
            });
        };
    
        return methods;
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作