Results 1 to 3 of 3

Thread: Not able to PUT json array in Ext.ajax.request

  1. #1
    Sencha User
    Join Date
    Dec 2008
    Posts
    8
    Vote Rating
    0
      0  

    Default Not able to PUT json array in Ext.ajax.request

    Hi All,

    I try to send an array of json object to the server:

    Code:
                Ext.Ajax.request({
                    url: '../rest/admin/group/',
                    method: 'PUT', 
                    headers: {'Content-Type': 'application/json'},
                    params: {
                        sorts: Ext.JSON.encode([{"property":"name","direction":"ASC"}]) 
                    },
                    success: function(response) {
                        ...
                    }    
                });
    The server uses Spring MVC to handle the request:
    Code:
            binder.registerCustomEditor(Sort.class, new JsonPropertyEditor(Sort[].class));
    
    ...
    
        @RequestMapping(value = "/group", method = RequestMethod.PUT)
        public View removeUsers4Group(Model model, 
                @RequestBody Sort[] sorts) {
    ...
    }
    I get the 404 error (bad request) and the request never reaches the handler. However, if it is a request param, the object get parsed correctly:

    Code:
                @RequestParam(value = "sort", required = false) final Sort[] sorts, Model model) {
    I am using extjs 4.1.1a. Any help will be appreciated.

    Thanks,
    -ZJ

  2. #2
    Sencha - Sr Software Engineer mitchellsimoens's Avatar
    Join Date
    Mar 2007
    Location
    Gainesville, FL
    Posts
    39,556
    Vote Rating
    1272
      0  

    Default

    Check out the network tab in browser dev tools. The params will be sent as form data
    Mitchell Simoens @LikelyMitch
    Sencha Inc, Senior Software Engineer
    ________________
    Learn BBCode and use it! Checkout the CODE tag!

    Check out my GitHub, lots of nice things for Ext JS and Sencha Touch
    https://github.com/mitchellsimoens

  3. #3
    Sencha User
    Join Date
    Dec 2008
    Posts
    8
    Vote Rating
    0
      0  

    Default

    It looks like that I have to use 'jsonData' instead of 'params' to make it work with Spring @RequestBody.

    Thank you very much for your reply.

    -ZJ

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •