title: Mapping Ajax Request in Spring MVC: getting error 405 method not allowed
body: <p>After making the ajax call I am getting error 405 method not allowed. I am using Spring 3.0.1, Spring-web 3.0.1. </p>
  
  <p>Here is the controller mapping</p>
  
  <p>@Controller
  public class AjaxController {</p>
  
  <pre><code>@RequestMapping(value = "/ajaxaction",
         method = RequestMethod.POST,
                   headers ="content-type=application/json")
  public @ResponseBody Collection&lt;Employee&gt; serveAjaxRequest(@RequestBody ReqParam reqParam){
      List&lt;Employee&gt; empList = new ArrayList&lt;Employee&gt;();
      System.out.println("Req obj:: " + reqParam.getA() + " " + reqParam.getB()
              + " " + reqParam.getC() + " " + reqParam.getD() + " " + reqParam.getE());
      Employee e1 = new Employee();
      e1.setFirstName("Vaibhav");
      e1.setLastName("Raj");
      e1.setEmail("vraj3@sapient.com");
      e1.setTelephone("1111111111");
      e1.setReturnMessage("Message one!!");
      Employee e2 = new Employee();
      e1.setFirstName("Ajay");
      e1.setLastName("Singh");
      e1.setEmail("asingh@gmail.com");
      e1.setTelephone("2222222222");
      e1.setReturnMessage("Message two!!");
      empList.add(e1);
      empList.add(e2);
      return empList;
  }
  </code></pre>
  
  <p>)</p>
  
  <p>and the Jquery code for ajax call:</p>
  
  <p>function : submitAjax(){</p>
  
  <pre><code>$('#g').bind('click', function(evt) {
   alert($('form').serialize());
   formData = $('form').serialize();
   $.ajax({
   url: "/ajaxaction.html",
   type: 'POST',
   dataType: 'json',
   data: formData,
   success: function(data) {
            alert(data);
            },
   error: function(){
      alert("Error!!");
      }
     });
  
  });
  </code></pre>