Javascript SyntaxError:输入意外结束
我收到Javascript SyntaxError:输入意外结束,javascript,jquery,json,Javascript,Jquery,Json,我收到语法错误:输入意外结束。代码在我看来很好,我遗漏了什么 function SaveGridster(jsonState) { console.log('SaveGridster'); // I CAN SEE THIS IN CONSOLE var msttou = { "srno": "1", "module": "ABT Meter Details", "userid": "SYS"
语法错误:输入意外结束
。代码在我看来很好,我遗漏了什么
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);
}
});
}
控制台:
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)
错误似乎存在于函数得到的AJAX响应中。SyntaxError由JSON解析器发出。将数据类型转换为“text”以禁用JSON解析。这不是注释吗?可能是,但我还不能注释:(SaveGridster函数正在执行,这是肯定的。因为我可以在控制台中看到第一条控制台日志消息。如果在此代码之前出现问题,我认为此函数不会正确执行?您是对的。您看到的错误消息似乎是由AJAX响应的解析引起的。您能检查一下吗开发人员工具?您是否可以尝试使用数据类型“text”发出相同的请求?