Sunday, October 11, 2015

Easy way to submit form data via ajax

Using jquery plug in from http://malsup.com/jquery/form/
.

Overview

The jQuery Form Plugin allows you to easily and unobtrusively upgrade HTML forms to use AJAX. The main methods, ajaxForm and ajaxSubmit, gather information from the form element to determine how to manage the submit process. Both of these methods support numerous options which allows you to have full control over how the data is submitted.Submitting a form with AJAX doesn't get any easier than this!

Quick Start Guide

1Add a form to your page. Just a normal form, no special markup required:
 id="myForm" action="comment.php" method="post">      Name:  type="text" name="name" />      Comment:        type="submit" value="Submit Comment" /> 
2Include jQuery and the Form Plugin external script files and a short script to initialize the form when the DOM is ready:
> 
> 
     
     
 
     
 
...
That's it!
When this form is submitted the name and comment fields will be posted to comment.php. If the server returns a success status then the user will see a "Thank you" message.
.

No comments: