Ajax- Submit Form Using Ajax Simple Example

Below is simple code for htmt and jQuey script.

HTML Code

 
First Name:
Last Name:
Email :

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
}); 

Note: Please be sure, jQuery library has included for the page.

Enjoy the day :) :)

No comments:

Post a Comment