javascript - 类型错误 : Cannot read property 'Result' of undefined

标签 javascript angularjs

我正在尝试显示数据库中的结果,但收到此错误消息

类型错误:无法读取未定义的属性“结果”

我正在使用 AngularJS 创建一个单页应用程序。结果位于 services.js 中。有人可以帮我解决这个错误吗?

这是我的 services.js 代码:

(function () {
'use strict';
/** Service to return the data */

angular.module('MovieApp').
    service('dataService',         // the data service name, can be anything we want
        ['$q',                     // dependency, $q handles promises, the request initially returns a promise, not the data
         '$http',                  // dependency, $http handles the ajax request
         function($q, $http) {     // the parameters must be in the same order as the dependencies

            /*
             * var to hold the data base url
             */
            var urlBase = '/cm0665-assignment/server/index.php';
            var loginUrl = '/cm0665-assignment/server/login.php';

            /*
             * method to retrieve courses, or, more accurately a promise which when
             * fulfilled calls the success method
             */
            this.getCategories = function () {
                var defer = $q.defer(),             // The promise
                    data = {
                        action: 'listCategory',
                        //subject: 'category'
                    };

                $http.get(urlBase, {params: data, cache: true}).                          // notice the dot to start the chain to success()
                    success(function(response){
                        defer.resolve({
                            data: response.ResultSet.Result,         // create data property with value from response
                            rowCount: response.RowCount  // create rowCount property with value from response
                        });
                    }).                                                 // another dot to chain to error()
                    error(function(err){
                        defer.reject(err);
                    });
                // the call to getCourses returns this promise which is fulfilled 
                // by the .get method .success or .failure
                return defer.promise;
            };

            this.getMovies = function (categoryid) {
                var defer = $q.defer(),
                data = {
                    action: 'listFilms',
                    //subject: 'films',
                    category_id: categoryid
                }
                $http.get(urlBase, {params: data, cache: true}).
                        success(function(response){
                            defer.resolve({
                                data: response.ResultSet.Result,
                                rowCount: response.RowCount
                            });
                        }).
                        error(function(err){
                            defer.reject(err);
                        });
                return defer.promise;
            };

            this.getActors = function (filmid) {
                var defer = $q.defer(),
                data = {
                    action: 'listActors',
                    film_id: filmid
                }
                $http.get(urlBase, {params: data, cache: true}).
                        success(function(response){
                            defer.resolve({
                                data: response.ResultSet.Result,
                                rowCount: response.RowCount
                            });
                        }).
                        error(function(err){
                            defer.reject(err);
                        });
                return defer.promise;
            };

            this.getAllMovie = function () {
                var defer = $q.defer(),
                data = {
                    action: 'listFilms'
                }
                $http.get(urlBase, {params: data, cache: true}).
                        success(function(response){
                            defer.resolve({
                                data: response.ResultSet.Result,
                                rowCount: response.RowCount
                            });
                        }).
                        error(function(err){
                            defer.reject(err);
                        });
                return defer.promise;
            };

            this.getSearchResult = function () {
                var defer = $q.defer(),
                data = {
                    action: 'search',
                    // term: terms
                }
                $http.get(urlBase, {params: data, cache: true}).
                        success(function(response){
                            defer.resolve({
                                data: response.ResultSet.Result,
                                rowCount: response.RowCount
                            });
                        }).
                        error(function(err){
                            defer.reject(err);
                        });
                return defer.promise;
            };

            this.login = function (userID, passwd) {
                var defer = $q.defer(),
                data = {
                  //action: 'loginRob',
                  userid: userID,
                  password: passwd
                };

                $http.post(loginUrl, data). // notice the dot to start the chain to success()
                    success(function (response) {
                        defer.resolve({
                            data: response.status, // create data property with value from response
                            result: response,
                            user: response.username
                        });
                        console.log(response);
                    }). // another dot to chain to error()

                    error(function (err) {
                        defer.reject(err);
                    });
                return defer.promise;
            };

         }
        ]
    );
}());

结果集的每一行都显示此错误。这意味着每次我单击其他导航选项卡时,我都会显示此错误消息。我真的需要有人在这方面提供帮助。预先感谢您。

最佳答案

您收到此错误是因为您试图取消引用未定义的变量。在本例中,它看起来是由以下语句引起的:response.ResultSet.Result。该错误表明 response.ResultSetundefined

这意味着服务器的响应不是您期望的格式,或者服务器端代码中存在错误。

关于javascript - 类型错误 : Cannot read property 'Result' of undefined,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36242955/

相关文章:

javascript - 在 Angularjs 中加载模块

javascript - 更改 Bootstrap Accordion 面板的宽度(折叠元素)

javascript - 如何在 Hexo 源文件中使用 helpers?

javascript - 之前的web form录入数据后,如何让web form出现?

javascript - jquery如何检查url是否包含单词?

javascript - slickGoTo 不会更改事件幻灯片

javascript - 如何在 Angular JS 中自定义 $watch?

angularjs - TinyMCE <textarea> 与 AngularJS 的两种方式绑定(bind)

javascript - Angular 可编辑表不适用于 ng-repeat

javascript - 使用 Angular Resource 通过字符串参数查询 REST API