Submit Form Data Over AJAX - jQuery ajaxform

Submit Form Data Over AJAX - jQuery ajaxform
File Size: 7.58 KB
Views Total: 130
Last Update:
Publish Date:
Official Website: Go to website
License: MIT
   

A tiny and easy-to-use AJAX form jQuery plugin that sends form data (like files) via AJAX requests and returns response messages on submit.

How to use it:

1. Import the jquery.ajaxform.js script after loading the latest jQuery library.

<script src="/path/to/cdn/jquery.min.js"></script>
<script src="/path/to/src/js/jquery.ajaxform.js"></script>

2. Add the data-form="ajaxform" attribute to your HTML form and done. Note that browsers without FormData will uses iframe transport to send files.

<form id="example" method="post" action="/" enctype="multipart/form-data" data-form="ajaxform">
  <input name="name" id="name" type="text" />
  <input name="files[]" id="files" type="file" />
  <input type="submit" />
</form>

3. Add event handler for the submitajax event.

$(document).ready(function(){

  $('#example').submitAjax(function(event, data, textStatus, jqXHR){
    alert('submit ajax response:' + data);
  });

});

This awesome jQuery plugin is developed by gozoro. For more Advanced Usages, please check the demo page or visit the official website.