Announcement Announcement Module
Collapse
No announcement yet.
Problem with @ResponseBody and Jquery and String Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problem with @ResponseBody and Jquery and String

    I'm just not quite getting something.

    in my jsp:
    Code:
    $(document).ready(function() 
    {
    	$("#submit_selector_type").click(function() 
    	{
    		$.getJSON("https://localhost/webapps//jsonhowto/submit_selector_type",
    				{"y":$("#selector_type").val()},
    	                        function(data){$("#selector").val(data);}
    				);
    	});	
    });
    
    
    ....
    
    <input id="selector_type" type="text" value="none" ></input><br/>
    <input id="submit_selector_type" type="button" value="submit selector type"/><br/>
    <input id="selector" name="selector" type="text" value="this is the selector"/><br/>

    And my controller method is:
    Code:
        @RequestMapping("**/jsonhowto/submit_selector_type")
        public @ResponseBody String submitSelectorType(@RequestParam("y") String y)
        {        
            return "Helo World";
        }
    the value in selector never gets changed.

    However, if I change the callback line in the jsp to :

    Code:
    function(data){$("#selector").val(data.msg);}
    and make the controller method be this:
    Code:
        @RequestMapping("**/jsonhowto/submit_selector_type")
        public @ResponseBody JSONHowToMsg submitSelectorType(@RequestParam("y") String y)
        {
            JSONHowToMsg result = new JSONHowToMsg();
            result.msg = "Hello World";
    
            return result;
        }
    where JSONHowToMsg is this trivial thing:
    Code:
    public class JSONHowToMsg
    {
        public String msg;
    
        public String getMsg()
        {
            return msg;
        }
    
        public void setMsg(String msg)
        {
            this.msg = msg;
        }
    }
    then everything works like I'd expect it to.

    Can anybody explain this?

    This could be completely a jquery issue, but I found the Spring Forum first
Working...
X