title: Why jquery ajax form submit return error?
body: <p>Hi I am new to ajax and jquery and I need to submit a form with ajax when a button "mainbutton" is clicked. Here is my code</p>
  
  <pre><code>$(document).ready(function(){
              $("#mainbutton").click(function(){
                  $("#ajaxform").submit(function(e)
                  {
                      var postData = $(this).serializeArray();
                      var formURL = $(this).attr("action");
                      $.ajax(
                      {
                          url : formURL,
                          type: "POST",
                          data : postData,
                          success:function(data, textStatus, jqXHR) 
                          {
                              alert("success");
                          },
                          error: function(jqXHR, textStatus, errorThrown) 
                          {
                              alert("error");      
                          }
                      });
                      e.preventDefault(); //STOP default action
                  });
                  $("#ajaxform").submit(); //Submit the form
              });
          });
  </code></pre>
  
  <p>when I try that I get Error and my form is not submitted and my servlet doPost() is not called. Where is my mistake ? </p>