ModelAndView return in ajax spring mvc

Hi, I am using spring mvc + ajax. I made an ajax call, passing the user id. And everything is going well, successfully returning to ajax, but when I warn the answer, it just shows the html page code. Please help me deal with this issue. I think I did not code my ajax well. Help me right.

Controller Code:

  public @ResponseBody ModelAndView abc(HttpServletRequest httpServletRequest,
        HttpSession session, ModelMap map){

      ModelAndView modelAndView = new ModelAndView("abcd.page",
                "commandName", object);
           return modelAndView;

Ajax Code:

     $(".userDetails").click(function() {
            alert("clicked");
        var userId=$(this).parent().parent(). parent().find(".userId"). 
                       text().trim();
            alert("userId :"+userId);
            $.ajax({

            url : 'ABC.htm',
            type : 'GET',
            data: {userId:userId},
            beforeSend: function(xhr) {  
                xhr.setRequestHeader("Accept", "application/json");  
                xhr.setRequestHeader("Content-Type", "application/json");  
            },  
            success : function(response) {
                alert("success");
                alert(response);
            },
            error : function(res) {
                alert("error");
            },

        });

            return false;
        });

Exit for warning (response); is an enter image description here

EDIT: . Can anyone tell me why ajax provides html content for success ... After many changes, I got the same warning.

: , . , . . ModelAndView ajax

+4
1

ModelAndView AJAX. Spring HandlerMethodReturnValueHandler . ModelAndView ModelAndViewResolverMethodReturnValueHandler. @ResponseBody RequestResponseBodyMethodProcessor. , ModelAndView . , ModelAndView, Spring Model, , , jsp jsp, HTML. AJAX , HTML.

JSON, ModelAndView, JSON .

+9

All Articles