2017-02-28 32 views
0

私のデータがバックエンドに保存されているにもかかわらず、送信ボタンをクリックするとコンソールでこのエラーが表示されます。ここで位置0のJSONで予期しないトークンT

SyntaxError: Unexpected token T in JSON at position 0 
    at JSON.parse (<anonymous>) 
    at dc (angular.min.js:91) 
    at angular.min.js:92 
    at q (angular.min.js:7) 
    at gd (angular.min.js:92) 
    at f (angular.min.js:94) 
    at angular.min.js:131 
    at m.$digest (angular.min.js:142) 
    at m.$apply (angular.min.js:146) 
    at l (angular.min.js:97) 

は角

再び
$scope.nextStep = function() { 
     if ($scope.selection === 'Information'){ 
      $scope.branch.organisation = $scope.branch.organisation.id; 
      $scope.fact.incrementStep($scope); 
     } 
     else if ($scope.selection === 'Validation'){ 
      var authdata = base64.encode($rootScope.globals.currentUser.user.phone + ':' + $scope.password.password); 
      if (authdata === $rootScope.globals.currentUser.authdata){ 
       $scope.passwordMatch = true; 

       var branchArr = []; 
       var dynamicBranches = $scope.dynamicBranches; 

       for (var i = 0; i < dynamicBranches.length; i++) { 
        branchArr.push(dynamicBranches[i].name); 
       } 

       var params = [{ 
        "region" : $scope.branch.region, 
        "branches" : branchArr 
       }]; 

       Restangular.one('organisation', $scope.branch.organisation).all('add_region_and_branch_data').post(params).then(function(response) { 
        $scope.createdBranch = response; 
        $scope.fact.incrementStep($scope); 
       }, function(error){ 
        ///console.log('Error with status', error.statusText, 'code', error.status); 
        //SweetAlert.swal('Error', 'The agent couldn\'t be created. \n' + error.data.error, 'error'); 
        console.log(error); 
       }); 


      }else{ 
       $scope.passwordMatch = false; 
      } 
     } 
    }; 

で私のフロントエンドのコードで、私のデータは、APIに救われているが、私はこのエラーを取得しています。どうすればこの問題を解決できますか?

+1

警告を。あなたのサービスは何を返すのですか?彼らの側に何らかのエラーがあるため、おそらく無効なJSONです。 –

答えて

1

HTTP応答の本文を確認してください。 AngularJSはJSONのように解析できないものを取得します。警告やエラーが発生してAPIレスポンスに追加されることがありますか?私の問題はあなたのnextStep機能にはないのです。

Unexpected token T in JSON at position 0問題は、このHTTP-応答と、例えば、発生する可能性があります:

Too many params warning{"here": "is valid JSON"} 

それとも、あなたがデバッグする必要がある

Too many params warning 
+0

organisation_idを使って[{"region": "matlab"、 "branches":["B"、 "C"]}]形式でデータを送信する必要があります。 –

+0

@SalmanMahmud残念ながら、私はHTTP要求と応答のダンプなしであなたを助けることはできません。このリクエストのChrome DevTools Networkタブからデータを表示できますか? – Antonio

関連する問題