1

I have a trouble understand how @Responsebody work.

So I have a page call browse, and in the page, I have a button so that whenever the client click on the button, the page will load more data from the server.

current page URL: /myapp/browse button: Load more div: This is my jquery script:

$(document).ready(function(){
  $("#loadmore").click(function() {
    $.getJSON('browse', function(jd) {
        $("#result").append(jd);
    });
  });
});

And this is my server code:

@RequestMapping(value="/loadmore", method=RequestMethod.GET)
@ResponseBody
public String loadMore() {
    return "loadit";
}

So I expected that the page will stay as same as it is, and the string will be displayed in the div#result. However, the string is display in an empty page with the URL: /myapp/loadmore. Can any point out what did I do wrong please? Thank in advance.

Jason
  • 85
  • 2
  • 8

1 Answers1

0

You have to send your request to your controller;

$(document).ready(function(){
  $("#loadmore").click(function() {
    $.getJSON('/loadmore', function(jd) {
        $("#result").append(jd);
    });
  });
});
hurricane
  • 6,521
  • 2
  • 34
  • 44