title: Spring: Get the form object after an ajax request
body: <p>I try to submit a form in a ajax-way, with Spring. My code is :</p>
  
  <p>FilterForm is a simple Bean with getters/setters.</p>
  
  <pre><code>@Controller
  @RequestMapping("/mypage")
  public class MyPageController {
  
      @RequestMapping(value = "/", method = RequestMethod.GET)
      public String index(Model model) {
          model.addAttribute("filterForm", new FilterForm());
          return "configuration/home";
       }
  
      @RequestMapping(value = "/filter", method = RequestMethod.POST)
      public String filter(@ModelAttribute FilterForm filterForm, Model model) {
          model.addAttribute("filterForm", filterForm);
          return "fragments/configuration/filter-result";
      }
  }
  </code></pre>
  
  <p>The view home.html is:</p>
  
  <pre><code>        &lt;form action="#" th:action="@{/mypage/filter}" th:object="${filterForm}" method="post" id="filterForm"&gt;
              &lt;p&gt;Field : &lt;input type="text" th:field="*{field}" /&gt;&lt;/p&gt;
              &lt;p&gt;&lt;input type="submit" value="Submit" /&gt; &lt;input type="reset" value="Reset" /&gt;&lt;/p&gt;
          &lt;/form&gt;
  
          &lt;div id="filterResults"&gt;&lt;/div&gt;
  </code></pre>
  
  <p>The view filter-result is (by now):</p>
  
  <pre><code>&lt;span th:text="${filterForm.getField()}"&gt;&lt;/span&gt;
  </code></pre>
  
  <p>With only that, it works fine. But it isn't ajax. To submit the form in an ajax-way, it use:</p>
  
  <pre><code>$("#filterForm").submit(function(e) {
          e.preventDefault();
          var frm = $(this);
          $.ajax({
              contentType : 'application/json; charset=utf-8',
              type: frm.attr('method'),
              url: frm.attr('action'),
              dataType : 'html',
              data : frm.serialize(),
              success : function(callback){
                  $("#filterResults").html(callback);
              },
              error : function(e){
                  console.log('error');
                  console.log(e.status + ' ' + e.statusText);
              }
          });
      });
  </code></pre>
  
  <p>In this case, the attributes of filterForm, in the filter method, are null. In firebug, I can see that POST params are well formed, ie "field=anything". Can't figure why Spring cannot bind the request to the filterForm when it is ajax?</p>