首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >JSON中位置0处的意外标记T

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

Stack Overflow用户
提问于 2017-03-01 04:04:26
回答 1查看 1.9K关注 0票数 0

当我点击提交按钮时,我在控制台中得到了这个错误,尽管我的数据被保存到了我想要的后端。

代码语言:javascript
运行
复制
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)

以下是我在angular中的前端代码

代码语言:javascript
运行
复制
  $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,但是我得到了这个错误。我该如何解决这个问题呢?

EN

回答 1

Stack Overflow用户

发布于 2017-03-01 04:12:31

检查您的HTTP响应正文。AngularJS得到了一些它不能像JSON那样解析的东西。是否有任何警告或错误发生并添加到您的API-response中?我认为问题不在您的nextStep函数中。

Unexpected token T in JSON at position 0问题可能会发生,例如,使用以下HTTP响应:

代码语言:javascript
运行
复制
Too many params warning{"here": "is valid JSON"}

或者仅仅是警告

代码语言:javascript
运行
复制
Too many params warning
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42517743

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档