Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/angularjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Angularjs JSON中位于位置0处的意外标记T_Angularjs_Json - Fatal编程技术网

Angularjs JSON中位于位置0处的意外标记T

Angularjs JSON中位于位置0处的意外标记T,angularjs,json,Angularjs,Json,当我点击提交按钮时,我在控制台中遇到了这个错误,尽管我的数据正在按照我的要求保存到后端 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)

当我点击提交按钮时,我在控制台中遇到了这个错误,尽管我的数据正在按照我的要求保存到后端

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)
SyntaxError:JSON中位于位置0的意外标记T
在JSON.parse()处
直流时(角度:91)
在角度上。最小js:92
在q处(角度:7)
在gd处(角度:92)
在f(角度最小:94)
在角度处。最小js:131
m.$digest时(angular.min.js:142)
在m.$apply(angular.min.js:146)
在l(角度最小: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;
            }
        }
    };
$scope.nextStep=function(){
如果($scope.selection==='Information'){
$scope.branch.organization=$scope.branch.organization.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 Branchharr=[];
var dynamicBranches=$scope.dynamicBranches;
对于(var i=0;i

同样,我的数据被保存到api,但我得到了这个错误。如何修复此问题?

检查您的HTTP响应正文。AngularJS得到了它无法解析的东西,比如JSON。是否发生任何警告或错误并将其添加到API响应中?我想问题不在
nextStep
函数中

位置0处JSON中意外的标记T
问题可能会发生,例如,使用以下HTTP响应:

Too many params warning{"here": "is valid JSON"}
或者只是警告

Too many params warning

你需要调试。你的服务回报是什么?由于JSON方面的一些错误,它可能是无效的。我需要以[{“region”:“matlab”,“Branchs”:[“B”,“C”]}]格式发送数据,并带有组织id。@SalmanMahmud不幸的是,没有HTTP请求和响应转储,我无法帮助您。您能显示来自Chrome DevTools网络选项卡的此请求的数据吗?