2017-04-22 77 views
0

這是我的腳本Angularjs和PHP錯誤

<script> 
var app = angular.module('myApp', []); 
app.controller('customersCtrl', function($scope, $http) { 
    $http.get("http://ip/ss.php") 
    .then(function (response) {$scope.names = response.data.records;}); 
}); 
</script> 

幫助我,請

編輯:這是確切的錯誤

錯誤:[$ HTTP:baddata]數據必須是有效的JSON目的。收到:「{」記錄「:[{」Time「:」ADV 360「,」Count「:」name「},{」Time「:」CCE 401「,」Count「:」name「}解析錯誤: 「{」 描述 「:」 無效字符 「 」數量「: - 2146827274, 」堆「:」 語法錯誤:在fromJson無效字符\ N(https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.js:1431:3)\ n在defaultHttpResponseTransform(https://ajax.googleapis.com/ajax/libs/angularjs/1.6.4/angular.js:11175:11)\ n

+0

不要加載最小化的angularjs'angular.min .js',而是加載'angular.js' d您將能夠看到明確的錯誤 –

+0

您是否從$ http請求獲得任何響應。 – lakshay

+0

我裝使用angular.js相同error.No我沒有得到我爲什麼要尋找解決這個錯誤任何迴應 –

回答

1

嘗試使用下面的代碼,這將響應抓到確切的錯誤信息。或者,如果你得到響應,那麼檢查它在控制檯如下。

<script> 
    app.controller('customersCtrl', function($scope, $http) { 
     $http.get("http://ip/ss.php") 
     .then(function (response) { 
      angular.fromJson(response); 
      console.log(JSON.sringify(response)); 
      $scope.names = response.data.records;}, 
      function(error) {console.log(JSON.sringify(error));} 
     ); 
    }); 
    </script> 

`

+0

我更新angularjs版本後剛開確切的錯誤:[$ HTTP:baddata ]數據必須是有效的JSON對象。收稿日期:「{」記錄「:[{」時代「:」 ACC 201" ,‘伯爵’:‘名字’}, –

+0

我已經編輯我的代碼,如果是語法錯誤,然後angular.fromJson(響應)將轉換你對對象的迴應。 –