简体   繁体   中英

$.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!

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM