gpt4 book ai didi

javascript - AngularJS 语法错误 : Unexpected token {

转载 作者:行者123 更新时间:2023-11-28 13:21:14 26 4
gpt4 key购买 nike

我有一个有效的代码,但是当我检查控制台时,我收到 SyntaxError: Unexpected token { ,这是屏幕截图:

enter image description here

当我检查我的 studentController.js第 58 行时,它是 console.log(error);。完整代码为:

angular
.module('studentInfoApp')
.factory('Student', Student)
.controller('StudentsController', StudentsController)
.config(config);

function config($routeProvider) {
$routeProvider
.when('/', {
controller: 'StudentsController',
templateUrl: 'app/views/student-list.html'
})
}

function Student($resource) {
return $resource('/students/:id');
}

function StudentsController(Student, $scope, $http) {

$scope.inputForm = {};
$scope.students = null;

function initStudents() {
Student.query(function(data, headers) {
$scope.students = data;
$scope.studentsPanel = true;
console.log(data);
}, function (error) {
console.log(error);
});
}

initStudents();

$scope.addStudentForm = function() {
$scope.loading = true;
}

$scope.cancelAddStudent = function() {
$scope.loading = false;
}

$scope.addStudent = function() {
$scope.studentsPanel = false;
var data = {
fname: $scope.inputForm.fname,
lname: $scope.inputForm.lname,
age: $scope.inputForm.age,
email: $scope.inputForm.email
}

Student.save(data)
.$promise.then(function successCallback(response) {
initStudents();
console.log(response); //line 58
}, function errorCallback(error) {
console.log(error);
});
}
}

我在这里遗漏了什么吗?谢谢。

更新:

设法通过更正一些变量来修复它。在我的 php 文件中:

$request = Slim\Slim::getInstance()->request();
$data = json_decode($request->getBody());
echo json_encode($data);

应该是

echo json_encode($request); 

最佳答案

您的 json 响应不是有效的 JSON 格式。解决这个问题。

关于javascript - AngularJS 语法错误 : Unexpected token {,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32886027/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com