Announcement Announcement Module
Collapse
No announcement yet.
Posting JSON data to server using DOJO Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Posting JSON data to server using DOJO

    I have a question on submitting JSON data to server using DOJO. I have JSON data in the below format :
    Code:
    {"description":"vice-president"} ---> This is stored in a javascript variable jsonData
    The AJAX call is as below :
    Code:
    dojo.xhrPost({
       url : url, -- > url to the controller (/myContextRoot/getJsonData.do)
       content : jsonData,
       headers : {
            "Content-Type" : "application/json,charset=utf-8"
       },
       load: function(response,ioargs) {
            alert('success');
       },
       error : function(response,ioargs) {
            alert('error');
       }
    });
    In my controller, I have written a method as folllows :
    Code:
        @RequestMapping(value = "/getJsonData.do",method=RequestMethod.POST)
        public @ResponseBody String getJsonData(@RequestBody SampleVO sampleVO) {
             System.out.println("Inside controller");
             return "success";
        }
    And my value object is below :
    Code:
       public class SampleVO implements Serializable {
             private String description;
    
             getter/setter for the above.
       }
    When I perform an AJAX call to post the JSON data to the server, I am getting the error :
    org.codehaus.jackson.JsonParseException : Unexpected character ('j' (code 106)) : expected a valid value (number,string,array,object,'true','false' or 'null')

    I am using DOJO 1.5 and Spring 3.0

    Greatly appreciate if you guys can help me find the root cause.

    Thanks!
    Last edited by chaitu; May 17th, 2011, 10:44 AM.

  • #2
    I got the issue solved, have to use postData instead of content in the AJAX call.

    Comment

    Working...
    X