gozoro/jquery-ajaxform

A jQuery plugin to submit forms with files via AJAX and to get a response with errors.

Installs: 91

Dependents: 1

Suggesters: 0

Security: 0

Stars: 2

Watchers: 2

Forks: 0

Open Issues: 0

Language:JavaScript

Type:plugin

v1.0.1 2021-03-30 19:44 UTC

This package is auto-updated.

Last update: 2024-04-29 03:54:10 UTC


README

A jQuery plugin to submit form with files via AJAX and to get a response with errors. Browsers without FormData uses iframe transport to send files.

jquery-ajaxform attaches callback hooks to a form's submit event.

Requirements

  • jQuery version 1.7.0 and up

Installation

composer require gozoro/jquery-ajaxform

Usage

Reference the plugin and jQuery:

<script src='/resources/js/jquery.js' type='text/javascript'></script>
<script src='/resources/js/jquery.ajaxform.js' type='text/javascript'></script>

Declare your form as usual:

<form id="myform" 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>

And javascript:

<script type="text/javascript">
	$(document).ready(function(){

		// Add event handler for "submitajax" event
		$('#myform').submitAjax(function(event, data, textStatus, jqXHR){

			alert('submit ajax response:' + data);

		});
	});
</script>