Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HTTP status 406 - Please HELP!!! Spring+Ajax+JSON

 
Tony Ghy
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm facing a problem while trying to retrieve a Collection of Object (List<MyObject>) through Ajax call using Jquery.

My jsp where i make a call is :


The getCities is mapped to the following:


I believe the problem lies here: @ResponseBody is not able to automatically convert the List value into JSON format & hence i get the following error:


Please guide me.
I used Firbug to see what's going on. Here's what i get:


Please Help me. I'm stuck.
 
Mark Spritzler
ranger
Sheriff
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That is because you are doing a POST. a POST in REST means you are creating a new object. You are not, you want to GET the List. So you have to do a GET in order for it to work.

In a POST, the accept header is not requesting any type/format back, the response should only have the success status set and the URI to then GET what just got created. So the Body of a POST is always empty.

a GET is the only RequestMethod type to return data in the Body.

an Update and a Delete only return the status.

Hope that helps

Mark
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic