title: Returning ModelAndView in ajax spring mvc
body: <p>Hi am using spring mvc + ajax. I made a ajax call by passing a userid. And everything goes fine successfully returned to ajax but when i alert the response its simple showing the html page code. Please help me to sort out this prob.
  I think i didnt coded my ajax well.Help me to in correct way</p>
  
  <p>Controller code:</p>
  
  <pre><code>  public @ResponseBody ModelAndView abc(HttpServletRequest httpServletRequest,
          HttpSession session, ModelMap map){
  
        ModelAndView modelAndView = new ModelAndView("abcd.page",
                  "commandName", object);
             return modelAndView;
  </code></pre>
  
  <p>Ajax code :</p>
  
  <pre><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;
          });
  </code></pre>
  
  <p>The output for the alert(response); is
  <img src="https://i.stack.imgur.com/F3mov.png" alt="enter image description here"></p>
  
  <p><strong>EDIT:</strong> Can any one please tell why ajax giving html content on success... After many changes i made getting the same alert.</p>
  
  <p><strong>Edited Again :</strong> I think i dont have any problem in controller. Please suggest me solution to code my ajax correctly. It seems error here. How to get a ModelAndView object in ajax</p>