0

I´m trying to send an json object to my Spring MVC Controller using JQuery load.

If I do with POST as is described here How to pass Json object from ajax to spring mvc controller? I can make it works.

But If I try with load, since I cannot specify the content-type, my controller cannot serialize the object since the format is application-www. Any idea how to specify in a load the content type?.

Regards.

Community
  • 1
  • 1
paul
  • 10,286
  • 17
  • 68
  • 115
  • Try converting json object to string and then try to send. At other end do the opposite.. – Paras Mittal Oct 09 '14 at 13:36
  • I try already with JSON.stringify(json), but then the controller tell me "spring mvc Content type 'application/octet-stream' not supported" – paul Oct 09 '14 at 13:55

1 Answers1

0

jQuery .load uses HTTP GET Method. This method is not great for passing json. It is better to just pass parameters in the query string. If you do need to pass json, you can use stringify method as suggested above and pass json in the query string.

jny
  • 7,433
  • 3
  • 29
  • 52
  • Sorry but I dont understand what do you mean with ".load expects html. If you want to get json, you should use .get" I´m sending a json object to my controller, but as parameter. That call will render a modelAndView to be loaded in the proper div – paul Oct 09 '14 at 13:54
  • I try already with JSON.stringify(json), but then the controller tell me "spring mvc Content type 'application/octet-stream' not supported" – paul Oct 09 '14 at 14:53
  • From jQuery doc - `The POST method is used if data is provided as an object; otherwise, GET is assumed.` – LP13 Apr 27 '17 at 22:03