未捕获的SyntaxError:意外的令牌e [英] Uncaught SyntaxError: Unexpected token e
问题描述
我新收到了Uncaught Syntax Error,唯一的增加就是从服务器向客户端发送/检索json数据.如何调查这是什么?以下是屏幕截图
I am getting Uncaught Syntax Error newly, the only addition is sending/retrieve json data from server to client. How to investigate what it is? Below is the screen shot
有时我在谷歌浏览器中遇到以下错误.
Sometimes i get the following error in google chrome.
下面有我最近更新到我的代码的详细信息,然后才收到此错误.
Below have the details which i lately updated to my code before we get this error.
// Post the topic in the post section
function updatePost(xhr, status,jsonData){
var args = $.parseJSON(jsonData);
从服务器日志打印出来的数据,然后再发送给客户端
10:20:15,101 INFO [stdout] (http--127.0.0.1-8080-14) Printing json data {
10:20:15,102 INFO [stdout] (http--127.0.0.1-8080-14) "topic_username" : "srikanth marni",
10:20:15,102 INFO [stdout] (http--127.0.0.1-8080-14) "topic_lstUpdate" : "2012-09-06 10:20:15.025",
10:20:15,103 INFO [stdout] (http--127.0.0.1-8080-14) "topic_body" : "Whats up",
10:20:15,104 INFO [stdout] (http--127.0.0.1-8080-14) "isValid" : "true"
10:20:15,105 INFO [stdout] (http--127.0.0.1-8080-14) }
创建Json对象的服务器代码
stringWriter = new StringWriter();
// jfactory.createJsonGenerator(writer, JsonEncoding.UTF8);
jGenerator = jfactory.createJsonGenerator(stringWriter);
jGenerator.useDefaultPrettyPrinter();
jGenerator.writeStartObject(); // {
jGenerator.writeStringField("topic_username", loginUserName); // "title" : title
jGenerator.writeStringField("topic_lstUpdate", topicBean.getTopicVO().getLastUpdatedTimestamp().toString());
jGenerator.writeStringField("topic_body", topicBean.getTopicVO().getBody());
jGenerator.writeStringField("isValid", "true");
jGenerator.writeEndObject(); // }
jGenerator.close();
//String jsonData = topicBean.getTopicVO().getBody();
request.setAttribute("JSON_DATA", stringWriter.toString());
System.out.println(" Printing json data " +stringWriter.toString());
RequestDispatcher rd = servletContext.getRequestDispatcher("/meteor");
控制台中显示Json Parser错误
Uncaught SyntaxError: Unexpected token e jquery.js.jsf:16
bF.extend.parseJSON jquery.js.jsf:16
updatePost circle_topic.js.jsf:216
request.onMessage publish_subscribe.js.jsf:56
_f jquery.atmosphere.js.jsf:1975
_invokeFunction jquery.atmosphere.js.jsf:1967
_invokeCallback jquery.atmosphere.js.jsf:2027
AtmosphereRequest.ajaxRequest.onreadystatechange jquery.atmosphere.js.jsf:1438
JSON数据
Logging message from publish_subsrcibe :{
"topic_username" : "srikanth marni",
"topic_lstUpdate" : "2012-09-06 11:52:59.966",
"topic_body" : "testing",
"isValid" : "true"
}
推荐答案
这可能有用,也可能没有帮助,但是当外部系统调用的处理程序因语法错误而失败时,我也遇到了意外令牌E"错误.
This may or may not be helpful, but I also ran into the "Unexpected Token E" error when a handler for an external system call failed with a syntax error.
function handleSubsystemResult(text) {
// Chrome reported "Unexpected token E" here
var something = JSON.parse(text);
...
}
function main() {
...
callExternSubsystem( "externalSubsystemCode()", handleSubsystemResult );
}
外部子系统代码因语法错误而失败. Chrome仅在尝试对结果进行JSON.parse()时报告错误.如果在某种处理程序中调用了JSON.parse(),我将仔细检查谁调用了该处理程序.
The external subsystem code failed with a syntax error. Chrome reported the error only when trying to JSON.parse() the result. If the JSON.parse() is called in a handler of some sort, I'd examine who called that handler closely.
这篇关于未捕获的SyntaxError:意外的令牌e的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!