我有工作,但是當我檢查我的控制檯我越來越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嗎? –