当我单击提交按钮时,尽管我的数据已按照我的意愿保存到后端,但我在控制台中收到此错误。
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 前端代码
$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,但我收到此错误。我该如何解决这个问题?
最佳答案
检查您的 HTTP 响应正文。 AngularJS 得到一些它无法解析的东西,比如 JSON。是否可能发生任何警告或错误并添加到您的 API 响应中?我认为问题不在您的 nextStep
函数中。
JSON 中位置 0 处的意外标记 T
问题可能会发生,例如,使用以下 HTTP 响应:
Too many params warning{"here": "is valid JSON"}
或者只是警告
Too many params warning
关于angularjs - JSON 中位置 0 处出现意外标记 T,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47318813/