title: Jquery calling get method of spring controller in place of post
body: <p>I am trying to call a post method of my Spring MVC controller using POST method and here is the method of my controller</p>
  
  <pre><code>@Controller
  @RequestMapping("springSecurity/login.json")
  public class SpringSecurityLoginController
  {
  
      @RequestMapping(method = RequestMethod.GET)
          @ResponseBody
          public SpringSecurityLoginStatus getStatus()
          {
              return springSecurityLoginService.getStatus();
          }
  
          @RequestMapping(method = RequestMethod.POST)
          @ResponseBody
          public SpringSecurityLoginStatus login(@RequestParam("j_username") final String username,
                  @RequestParam("j_password") final String password, final HttpServletRequest request, final HttpServletResponse response)
          {
  
              LOG.info("Starting login process");
              return springSecurityLoginService.login(username, password, request, response);
          }
  }
  </code></pre>
  
  <h2>HTML</h2>
  
  <pre><code>&lt;form:form action="${request.contextPath}/j_spring_security_check" class="login-form " id="loginForm"  method="post" commandName="loginForm"&gt;
  
  &lt;form:input path="j_username" class="text" id="login_id" value="" name ="j_username"/&gt;
  &lt;form:password path="j_password" class="text" value="Password" name="j_password" id="j_password"/&gt;
  &lt;input type="submit" class="submit" value="LOGIN" id="login" /&gt;
  &lt;/form:form&gt;
  </code></pre>
  
  <p>and here is my Jquery code</p>
  
  <pre><code>jQuery("#login").live('click', function(e) {
          e.preventDefault();
  
          jQuery.ajax({url: getHost() + "${request.contextPath}/springSecurity/login.json",
              type: "POST",
              beforeSend: function(xhr) {
                  xhr.withCredentials = true;
              },
              data: jQuery("#loginForm").serialize(),
              success: function(data, status) {
                  if (data.loggedIn) {
                     // location.href = getHost() + '${ctx}/users';
                      //login_pannel
  
                  } else {
                      loginFailed(data);
                  }
              },
              error: loginFailed
          });
      });
  </code></pre>
  
  <p>But the above code is calling </p>
  
  <pre><code>@RequestMapping(method = RequestMethod.GET)
  @ResponseBody
  public SpringSecurityLoginStatus getStatus()
  </code></pre>
  
  <p>and not </p>
  
  <pre><code>@RequestMapping(method = RequestMethod.POST)
  @ResponseBody
  public SpringSecurityLoginStatus login(@RequestParam("j_username") final String username,
  @RequestParam("j_password") final String password, final HttpServletRequest request, final HttpServletResponse response)
  </code></pre>
  
  <p>i am not sure why this behavior is occuring</p>