2016-03-27 18 views
0

のプロパティ「結果」を読み取ることができません私は、データベースからの結果を表示しようとしていますが、私はAngularJSを使用して単一ページのアプリケーションを作成していますこのエラーメッセージはTypeError:未定義

TypeError: Cannot read property 'Result' of undefined

を取得しています。結果は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; 
      }; 

     } 
     ] 
    ); 
}()); 

のResultSetのそれぞれの行は、このエラーを示しています。これは、別のナビゲーションタブをクリックするたびにこのエラーメッセージが表示されることを意味します。私は本当に誰か助けが必要です。前もって感謝します。

+0

このエラーは、定義される前に 'result'にアクセスしていることを示します。別のケースでは、場合によっては未定義の場合は 'if-else'条件を使用して処理します。 –

+0

しかし、コードは昨日働いていた。それ以降は何も変わらなかった。構文エラーですか? – anonymous5671

+0

私はmozillaで同じコードを実行しても、動作していてもクロムでは機能していないことを知りました。 – anonymous5671

答えて

0

undefinedという変数を参照解除しようとしているため、このエラーが発生しています。この場合は、次の文によって引き起こされたようです:response.ResultSet.Result。エラーはresponse.ResultSetundefinedであることを示します。

これは、サーバーからの応答が期待どおりの形式でないか、サーバー側のコードにバグがあることを意味します。

+0

ブラウザでキャッシュをクリアした後の動作 – anonymous5671

関連する問題