質問

I have the following JSON

["2848","241"]

By using following jquery code

var list = [];
    $.each($("input[class='selected']:checked"), function(){
        list.push($(this).val());
    });

I am sending this data to my spring controller by using following in ajax post request.

var jsonData = JSON.stringify(list);

My spring controller is as follows

@RequestMapping(value="/myurl", method =  RequestMethod.POST)
    public String sampleMethod(@RequestBody String jsonData){
        Type dataType = new TypeToken<List<String>>(){}.getType();
        List<String> myListObject = gson.fromJson(jsonData, dataType);
        System.out.println(myListObject.size());
        return "redirect:/someotherurl";
    }

I get 500 internal server error for some reason but no stack trace or errors on my console in browser. Please suggest what is missing.?

役に立ちましたか?

解決

Fixed it by adding contentType: "application/json" to my ajax request. The server was not interpreting the json data properly.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top