簡體   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