我有工作,但是当我检查我的控制台我越来越SyntaxError: Unexpected token {
,这里是截图代码:AngularJS语法错误:意外标记{
当我检查我的studentController.js
的line 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);
});
}
}
我在这里错过了什么吗?谢谢。
UPDATE:
管理通过校正一些变量来解决它。 在我的PHP文件:
$request = Slim\Slim::getInstance()->request();
$data = json_decode($request->getBody());
echo json_encode($data);
应该
echo json_encode($request);
'var data = {...}'后面是否需要分号? – JackalopeZero
@JackalopeZero有或没有,仍然一样.. – FewFlyBy
你可以做jsfiddle吗? –