title: How to get all request parameter names and values in a form submitted using ajax in spring MVC?
body: <p>I am submitting a form in spring g MVC using ajax. The form is being generated dynamically. Hence I do not know  the names of the request parameters submitted in the form. </p>
  
  <p>In a simple form submission (not Ajax), I used to get all the parameter names and their values using the following code. </p>
  
  <pre><code>Enumeration requestParameters = request.getParameterNames();
  while (requestParameters.hasMoreElements()) {
      String element = (String) requestParameters.nextElement();
      String value = request.getParameter(element);
  }
  </code></pre>
  
  <p>But the same code does not work when I submit the form using ajax. Below is the code I am using to submit the form using ajax.</p>
  
  <pre><code>$.post("saveEntity", function() {
       alert("SUCCESS");
  });
  </code></pre>
  
  <p>And below is my controller class method which gets called on the form submission.</p>
  
  <pre><code>@RequestMapping(method = RequestMethod.POST, value = "/saveEntity")
  public @ResponseBody
  void saveEntity( HttpServletRequest request) {
  
      Enumeration requestParameters = request.getParameterNames();
  
      while (requestParameters.hasMoreElements()) {
          String element = (String) requestParameters.nextElement();
          String value = request.getParameter(element);
  
          if (element != null &amp;&amp; value != null) {
              logger.info("param Name : " + element
                      + " value: " + value);
  
          }
      }
  
  }
  </code></pre>
  
  <p>Is there anything that I am doing wrong or missing something? Please help. </p>