title: Spring Boot Ajax post form submit with model and thymeleaf
body: <p>I have a spring boot controller which returns a view and i wanted to change it by consuming an ajax endpoint, but at the same time get the values from the form with a modelAttribute and then send a list or multiple lists on the page and iterate through those lists with thymeleaf.Is it possible?
  Here is the controller:</p>
  
  <pre><code>@RequestMapping(value="/search", method=RequestMethod.POST)
      @ResponseBody
      public String search(@ModelAttribute("specification") Specification specification, Model model) {
  
          List&lt;SearchResultAutovit&gt; list;
  
          list = scrapper.searchMethod(specification.getPrice,specification.getModel);
  
          if (list == null || list.isEmpty()) { 
              model.addAttribute("msg","Something"); 
          } else { 
              model.addAttribute("listaAutovit", list); 
          }
          return "?";
      }
  </code></pre>
  
  <p>Ajax request:</p>
  
  <pre><code>$(".btn.btn-danger").on('click', {function fire_ajax_submit() {
      var str = $(".form-inline.justify-content-center").serialize();
  
      $.ajax({
          type:"post",
          data:str,
          url:"/search",
          async: false,
          dataType: "json",
          success: function(){
             alert("success");
          }
      });
  
  }
  </code></pre>
  
  <p>I don't want to manipulate the page from the ajax succes part because i'm already doing that with thymeleaf when the model is sent to the page.</p>