프로그램/spring

jQuery Ajax json Post

mulderu 2014. 2. 19. 14:45

 data post를  http body에 직접 하는 방법이 있다... 흔히  json post라고 하는데, 아래와 같이 처리 하면 된다.


Ajax Post Json Example)

Client Side)

    $.ajax({

              url: '<c:url value="/test/api/set" />',

              type: 'post',

              accept: 'application/json',

              contentType: 'application/json; charset=utf-8',

              data: JSON.stringify({'list': savedData}),

              dataType: 'json',

              success: function(data) {

                // success handle

              },

              error: function(jqXHR,textStatus,errorThrown) {

                // fail handle

              }

            });



Server Side )


    @RequestMapping(value = "/api/set", method = RequestMethod.POST, headers = "Accept=application/json")

    @ResponseBody

    public ReturnObject apiSet(@RequestBody JSONObject models) throws Exception 

    {

         // your code

    }



HTTP Header Dump)