jQuery Form Plugin

The jQuery Form Plugin allows you to easily and unobtrusively upgrade HTML forms to use AJAX

View on GitHub


Getting Started

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

  1. Add a form to your page. Just a normal form, no special markup required:
     <form id="myForm" action="comment.php" method="post">
       Name: <input type="text" name="name">
       Comment: <textarea name="comment"></textarea>
       <input type="submit" value="Submit Comment">
     </form>
    
  2. Include jQuery and the Form Plugin external script files and a short script to initialize the form when the DOM is ready:
     <html>
     <head>
       <script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
       <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.3.0/jquery.form.min.js" integrity="sha384-qlmct0AOBiA2VPZkMY3 2WqkHtIQ9lSdAsAn5RUJD/3vA5MKDgSGcdmIv4ycVxyn" crossorigin="anonymous"></script>
    
       <script>
         // wait for the DOM to be loaded
         $(function() {
           // bind 'myForm' and provide a simple callback function
           $('#myForm').ajaxForm(function() {
               alert("Thank you for your comment!");
           });
         });
       </script>
     </head>
    

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.