Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Uncaught SyntaxError: Unexpected token e

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 enter image description here

Sometimes i get the following error in google chrome. enter image description here

Below have the details which i lately updated to my code before we get this error.

Java Script

// Post the topic in the post section
     function  updatePost(xhr, status,jsonData){
                    var args = $.parseJSON(jsonData);

Data printed from the server log before sending to client

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) }

Server code which creates Json Object

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 error show in console

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 Data

Logging message from publish_subsrcibe :{
  "topic_username" : "srikanth marni",
  "topic_lstUpdate" : "2012-09-06 11:52:59.966",
  "topic_body" : "testing",
  "isValid" : "true"
} 
like image 771
user1595858 Avatar asked Sep 06 '12 16:09

user1595858


1 Answers

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 );
}

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.

like image 160
J. Peterson Avatar answered Oct 18 '22 20:10

J. Peterson