[英]AngularJS SyntaxError: Unexpected token {
I have a code that works but when I check my console I'm getting SyntaxError: Unexpected token {
and here is the screenshot: 我有一个有效的代码,但是当我检查控制台时,出现
SyntaxError: Unexpected token {
,这是屏幕截图:
And when I check line 58
of my studentController.js
here it is console.log(error);
当我在这里检查
studentController.js
line 58
studentController.js
,它就是console.log(error);
. 。 The complete code is:
完整的代码是:
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);
});
}
}
Am I missing something here? 我在这里想念什么吗? Thank you.
谢谢。
UPDATE: 更新:
Managed to fix it by correcting some variable. 设法通过更正一些变量来修复它。 In my php file:
在我的php文件中:
$request = Slim\Slim::getInstance()->request();
$data = json_decode($request->getBody());
echo json_encode($data);
It should be 它应该是
echo json_encode($request);
Your json response is not in valid JSON
format. 您的json响应不是有效的
JSON
格式。 Fix that. 解决这个。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.