JSON中位于位置0的意外令牌T [英] Unexpected token T in JSON at position 0
问题描述
尽管我的数据已按我的意愿保存到后端,但是当我单击提交"按钮时,我在控制台中收到此错误.
I am getting this error in console when i click submit button though my data is getting saved to backend as i wanted.
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,但出现此错误.我该如何解决?
Again, my data is getting saved to api but I am getting this error. How can i fix this?
推荐答案
检查您的HTTP响应正文. AngularJS得到了一些无法解析的东西,例如JSON.可能发生任何警告或错误并将其添加到您的API响应中吗?我觉得问题不在您的nextStep
函数中.
Check your HTTP-response body. AngularJS gets something what it can't parse like JSON. May be any warning or error happened and added to your API-response? I thing a problem is not in your nextStep
function.
Unexpected token T in JSON at position 0
问题可能会发生,例如,使用以下HTTP响应:
Unexpected token T in JSON at position 0
problem can happen, for example, with this HTTP-responses:
Too many params warning{"here": "is valid JSON"}
或者只是警告
Too many params warning
这篇关于JSON中位于位置0的意外令牌T的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!