繁体   English   中英

AngularJS SyntaxError:意外令牌

[英]AngularJS SyntaxError: Unexpected token s

我有一个名为login的函数,当用户按下按钮时,将执行以下代码。

因此,我尝试查看用户是否存在,并在JSON对象中获取其数据,但这不起作用,我得到以下消息:

  SyntaxError: Unexpected token s
    at Object.parse (native)

URL完全像我想要的那样。

$scope.login = function() {
    var request = $http({
        method : "GET",
        url : "/REST/user" + "/" + $scope.email + "/" + "password" + "/" + $scope.password,
        headers : {
            'Content-Type' : "application/json"
        }
        });

    request.success(function(response) {
        location.href = "../views/test.html"
    });
    request.error(function(response) {
        growl.addErrorMessage("doesn't work", {
            ttl : 4000
        });
    });
}

浏览器输出

{
"id": "9be1804a-e366-11e4-9d4b-82ea0d805d53",
"email": "test@gmx.com",
"facebook_id": null,
"firstname": "test",
"lastname": "blabla",
"password": null,
"gender": null,
"is_active": "0",
"birthday": null
}

这个错误是由于JSON.parse在遇到一个键并非以引号"开头的对象时抛出错误。

例如:

{ abc: 123 }

会抛出“意外令牌a”。

默认情况下, $http会以"Content-Type": "application/json"或以{[开头的任何内容作为JSON,并调用JSON.parse

在开发者控制台的“网络”选项卡中查看响应,以了解可能触发了它的原因。

暂无
暂无

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

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