jquery - Spring MVC 415 Unsupported Media Type -


i using spring 3.2 , try use ajax post request submit array of json objects. if relevant, escaped special characters.

i getting http status of 415.

my controller is:

@requestmapping(value = "/save-profile", method = requestmethod.post,consumes="application/json")     public @responsebody string saveprofilejson(@requestbody string[] profilecheckedvalues){         system.out.println(profilecheckedvalues.length);         return "success";     } 

jquery is:

jquery("#save").click(function () {         var profilecheckedvalues = [];         jquery.each(jquery(".jsoncheck:checked"), function () {             profilecheckedvalues.push($(this).val());         });         if (profilecheckedvalues.length != 0) {             jquery("body").addclass("loading");             jquery.ajax({                 type: "post",                 contenttype: "application/json",                 url: contextpath + "/sample/save-profile",                 data: "profilecheckedvalues="+escape(profilecheckedvalues),                 datatype: 'json',                 timeout: 600000,                 success: function (data) {                     jquery('body').removeclass("loading");                 },                 error: function (e) {                     console.log("error: ", e);                     jquery('body').removeclass("loading");                 }             });         }     }); 

and example of 1 of objects array posting following json:

{   "id": "534213341",   "name": "jack lindamood",   "first_name": "jack",   "last_name": "lindamood",   "link": "https://www.facebook.com/jack",   "username": "jack",   "gender": "male",   "locale": "en_us",   "updated_time": "2013-07-23t21:13:23+0000" } 

the error is:

the server refused request because request entity in format not supported requested resource requested method 

why error happening - know?

you may try httpservletrequest. not have problem

  @requestmapping(value = "/save-profile", method = requestmethod.post,consumes="application/json",headers = "content-type=application/x-www-form-urlencoded")     public @responsebody string saveprofilejson(httpservletrequest request){        system.out.println(request.getparameter("profilecheckedvalues"));         return "success";     } 

Comments

Popular posts from this blog

image - ClassNotFoundException when add a prebuilt apk into system.img in android -

I need to import mysql 5.1 to 5.5? -

Java, Hibernate, MySQL - store UTC date-time -