Skip to content

vikaskamboj321/voj-webtech-ajax-form

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 

Repository files navigation

VOJ Ajax Form

VOJ Ajax Form is a jQuery Plugin that handle ajax requests of forms with minimum configurations ( be it a simple formor a multipart form ). Every feedback is welcome!

Installation

Include jQuery https://jquery.com

<script type="text/javascript" src="jquery.min.js"></script>

Include Bootstrap: https://getbootstrap.com

<link rel="stylesheet" type="text/css" href="bootstrap.min.css" />
<script type="text/javascript" src="bootstrap.min.js"></script>

Include Toastr-master( For Displaying Error/Success Messages): https://codeseven.github.io/toastr

<link rel="stylesheet" type="text/css" href="toastr.min.css" />
<script type="text/javascript" src="toastr.min.js"></script>

Include Plugin File:

<script type="text/javascript" src="jquery.ajax-form.min.js"></script>

Usage

Initialize Plugin

$("#form").ajaxSubmit();

if form contains any file

$("#form").ajaxSubmit({
  formdata:"filetype"
});

Possible Configurations

//default settings
var settings = {
  url : form.attr("action"),
	method: form.attr("method"),
	successCallback: function(data){
	  form.find('input, button, select, textarea').prop('disabled', false);
		if(data.success == true){
      toastr.success(data.message)
		}else{
		  toastr.error(data.message)
		}				
	},
	formdata: form.serialize(), // or "filetype"
	datatype: 'JSON',
	processdata: false,
	contenttype: false,
	reset: false,
	redirect: null
}
$("#form").ajaxSubmit(settings);

Sample Response

//for displaying success message
{
	"success":true,
	"message":"Form Submitted Successfully."
}
//for displaying error message
{
	"success":false,
	"message":"Some Unknown Error Occoured."
}

License

VOJ Ajax Form is licensed under the MIT license. (http://opensource.org/licenses/MIT)

About

VOJ Webtech Ajax Form

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published