未捕获的SyntaxError:意外的令牌{在位置96的JSON中

时间:2018-05-12 00:33:49

标签: javascript java json servlets

我正在创建一个允许用户登录的Web应用程序,我的数据库中有一些示例登录用户名/密码。我有一个login.js文件,它处理登录以发送到Java servlet并且工作正常,直到我尝试登录AWS服务器。现在我甚至不能让它在我的localhost上工作。我从来没有更改任何登录代码,因为它工作不起作用。

 /**
 * Handle the data returned by LoginServlet
 * @param resultDataString jsonObject
 */
function handleLoginResult(resultDataString) {
    resultDataJson = JSON.parse(resultDataString); //getting error here

    // If login success, redirect to index.html page
    if (resultDataJson["status"] === "success") {
        window.location.replace("index.html");
    }
    // If login fail, display error message on <div> with id "login_error_message"
    else {

        jQuery("#login_error_message").text(resultDataJson["message"]);
    }
}

/**
 * Submit the form content with POST method
 * @param formSubmitEvent
 */
function submitLoginForm(formSubmitEvent) {

    formSubmitEvent.preventDefault();

    jQuery.post(
        "login",
        jQuery("#login_form").serialize(),
        (resultDataString) => handleLoginResult(resultDataString)); //getting error here

}

// Bind the submit action of the form to a handler function
jQuery("#login_form").submit((event) => submitLoginForm(event));

0 个答案:

没有答案