当我点击提交按钮时,我在控制台中得到了这个错误,尽管我的数据被保存到了我想要的后端。
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,但是我得到了这个错误。我该如何解决这个问题呢?
发布于 2017-03-01 04:12:31
检查您的HTTP响应正文。AngularJS得到了一些它不能像JSON那样解析的东西。是否有任何警告或错误发生并添加到您的API-response中?我认为问题不在您的nextStep函数中。
Unexpected token T in JSON at position 0问题可能会发生,例如,使用以下HTTP响应:
Too many params warning{"here": "is valid JSON"}或者仅仅是警告
Too many params warninghttps://stackoverflow.com/questions/42517743
复制相似问题