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://cdnjs.cloudflare.com/ajax/libs/jquery.form/4.2.2/jquery.form.min.js" integrity="sha384-FzT3vTVGXqf7wRfy8k4BiyzvbNfeYjK+frTVqZeNDFl8woCbF0CYG6g2fMEFFo/i" crossorigin="anonymous"></script>
       <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" 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.