thilo.dev
thilo.dev

Reputation: 220

$.ajax unexpected token error on tomcat server (GWT)

we are currently working on a GWT Project and ran into an unexpected token error called by .parseJSON in this function after compiling and running the project on a tomcat server. In dev mode on eclipse this worked fine:

$.ajax({
  url: "index/sequences/seq.json",
  datatype: "json",
  }).success(function(data) {
var data = jQuery.parseJSON(data);
  });

This is the json; validated by jsonlint

{"cont":[{"values":"left arm up,turn left,sit","name":"greet&go"},{"values":"turn left,turn right,walk back","name":"strange moves"},{"values":"kick right,turn right, right arm up","name":"right moves"},{"values":"kick right,walk,sit","name":"sequnece 4"},{"values":"sit,stand,kick left","name":"up&down"},{"values":"stand,turn right,sit","name":"testin"},{"values":"turn left,kick right","name":"kickit!"},{"values":"turn right,look up,left arm out,walk","name":"greet the audience"}]}

After some debugging i realized, that the parseJSON is called two times; first time with no errors, right data and all, second time with empty data, what calls the error.

Any help welcome! THX!

Upvotes: 0

Views: 295

Answers (1)

Kevin B
Kevin B

Reputation: 95020

datatype should be dataType, and if you are supplying the dataType parameter (or passing the appropriate Content-Type: application/json header), you don't need to parse the json.

$.ajax({
  url: "index/sequences/seq.json",
  dataType: "json"
}).success(function(data) {
  console.log(data);
});

Upvotes: 2

Related Questions