deraemon
deraemon

Reputation: 71

Spring Controller calls another jsp page and pass the result as ajax response

I implement a button that call AJAX to request the data as follows.

        $(".load_comment").click(function() {

            $(this).parent().ajaxForm({
                success:function(data) {

                    $('#result').html(data);
                },
                dataType:"text"
            }).submit();
        });

Here is my controller to response AJAX request.

            @RequestMapping(value = "/get/", method = RequestMethod.POST)
            public @ResponseBody
            String get(HttpServletRequest request) {

                return "<pre>OK!</pre>";
            }

My source code works as expected. I get Text "OK!" showing in div #result.

I would like to know if it is possible to let the controller to call another jsp and return the jsp page result as AJAX response.

Thanks in advance.

Upvotes: 0

Views: 943

Answers (1)

deraemon
deraemon

Reputation: 71

My bad. It is simple.

            @RequestMapping(value = "/get/", method = RequestMethod.POST)
            public @ResponseBody
            ModelAndView get(HttpServletRequest request) {

                ModelAndView model = new ModelAndView("comment"); // call comment.jsp
            }

Upvotes: 0

Related Questions