Tuesday, May 19, 2015

Ajax- Simple Form Post Example

Ajax- Simple Form Post Example

<form name="ajaxform" id="ajaxform" action="ajax-form-submit.php" method="POST">
First Name: <input type="text" name="fname" value =""/> <br/>
Last Name: <input type="text" name="lname" value ="" /> <br/>
Email : <input type="text" name="email" value=""/> <br/>
</form>
 
 
<script>
jQuery("#ajaxform").submit(function(e)
{
 var postData = jQuery(this).serializeArray();
 var formURL = jQuery(this).attr("action");
 jQuery.ajax(
 {
  url : formURL,
  type: "POST",
  data : postData,
  success:function(data, textStatus, jqXHR) 
  {

  },
  error: function(jqXHR, textStatus, errorThrown) 
  {
  }
 });
    e.preventDefault(); //STOP default action
}); 
</script> 
 
 
Note: Please be sure, jQuery libary has included for the page.

Njoy the day :) :)  

No comments :

Post a Comment