문제

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