繁体   English   中英

AngularJS SyntaxError:意外令牌{

[英]AngularJS SyntaxError: Unexpected token {

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

在此处输入图片说明

当我在这里检查studentController.js line 58 studentController.js ,它就是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格式。 解决这个。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM