1

This is my spring controller

@RequestMapping(value = "/app/{appId}/save.html",method=RequestMethod.POST)
public @ResponseBody String myFunction 
     (@PathVariable("appId") String id, @RequestBody Map<String, String> data1) {
                return "hello";
   }

This is my ajax request

$.ajax({
                    type : 'POST',
                    url : '/app/${param.appID}/save.html',
                    data : JSON.stringify(myJsonData), 
                    dataType : "json",

                    success : function(data, textStatus,
                            xhr) {
                        var response = xhr.responseText;
                        if (response !== "hello") {
                            alert('sad');
                        } else {
                            alert('happy');
                        }
                    }
                });

The problem is , this request never reaches the controller and gets stuck . If I remove data and data1, things work fine. Can some help me with what am I doing wrong.

Update: Here's the error as shown by firebug

415 Unsupported Media Type : The server refused this request because the request entity is in a format not supported by the requested resource for the requested method ()

Here is my json object

myJsonData= {
                        "data1" : $("input[name=key1]:checked").val(),
                        "data2" : $("input[name=key2]:checked").val(),
                        "data3" : $("input[name=key3]:checked").val()
                };
4

2 回答 2

0

JSON.stringify没有必要。

data : myJsonData,

足够的。

于 2012-05-17T09:27:59.697 回答
0

尝试明确consumes="application/json"设置@RequestMapping

于 2012-05-18T04:41:58.010 回答