SyntaxError:意外的输入结束

时间:2016-04-14 08:33:59

标签: javascript jquery json

我得到了SyntaxError: Unexpected end of input。代码看起来很好,我缺少什么?

function SaveGridster(jsonState) {
        console.log('SaveGridster'); // I CAN SEE THIS IN CONSOLE
        var msttou = {
            "srno": "1",
            "module": "ABT Meter Details",
            "userid": "SYS",
            "jsondata": "jsonState"
        };


        $.ajax({
            type: "POST",
            contentType: "application/json;charset=utf-8",
            url: BaseAddress + "InstanceDataAPI",
            dataType: "json",
            data: JSON.stringify(msttou),
            success: function (response) {
                console.log('success');
            },
            error: function (xhr, status, error) {
                console.log(error);
                alert(xhr.responseText);
            }
        });
    }

CONSOLE:

SyntaxError: Unexpected end of input
    at Object.parse (native)
    at jQuery.extend.parseJSON (http://localhost:2402/Scripts/jquery-1.10.2.js:564:23)
    at ajaxConvert (http://localhost:2402/Scripts/jquery-1.10.2.js:8443:19)
    at done (http://localhost:2402/Scripts/jquery-1.10.2.js:8199:15)
    at XMLHttpRequest.callback (http://localhost:2402/Scripts/jquery-1.10.2.js:8792:8)

1 个答案:

答案 0 :(得分:5)

看起来错误在于你的函数得到的AJAX响应。 SyntaxError由JSON解析器发出。将dataType转换为' text'禁用JSON解析。