title: update the model by an Ajax call - Spring mvc
body: <p>please i insert data by ajax to my database in a page where i also have a table of records I inserted and in each time i add a data i want to update the content of the table. this is what i did : </p>
  
  <pre><code>@RequestMapping(value="/add_record",method=RequestMethod.POST)
  public @ResponseBody String addUser(@ModelAttribute User us,BindingResult result,ModelMap model){
      userservice.AddUser(us);
      model.addAttribute("usersystem", userservice.getAllUsers()); // &lt;== Here the problem
      return returnText = "you succefully add a record !" ;
  }
  </code></pre>
  
  <p>The Jquery function ;</p>
  
  <pre><code>function doAjaxPost() {
      var frm = $('#ajf');
      frm.submit(function (event) {
          event.preventDefault();
          $.ajax({
              type: "POST",
              url: "${pageContext.request.contextPath}/ajouter_user",
              data:  frm.serialize(),
              success: function(response){
                  // we have the response
                  $('#info').html(response);
              },
              error: function(e){
                  alert('Error: ' + e);
              }
          });
      });
  }
  </code></pre>
  
  <p>I don't know how can I return the attribute added by the controller to my jsp page, so i have always to refresh the page to see the new record.
  Thank you</p>
  
  <hr>
  
  <p>what if i use this way :</p>
  
  <pre><code>@RequestMapping(value="/add_record",method=RequestMethod.POST)
  public @ResponseBody ModelAndView addUser(@ModelAttribute User us,BindingResult result,ModelMap model){
      ModelAndView model = new ModelAndView("jspName");
      userservice.AddUser(us);
      model.addObject("usersystem", userservice.getAllUsers()); // &lt;== Here the problem
      return model;
  }
  </code></pre>
  
  <p>can i receive this model in the ajax call ??</p>