Skip to content

Instantly share code, notes, and snippets.

@chihebnabil
Created August 31, 2016 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chihebnabil/5cf45bfc7c10bca2e8371b7f9d7f577b to your computer and use it in GitHub Desktop.
Save chihebnabil/5cf45bfc7c10bca2e8371b7f9d7f577b to your computer and use it in GitHub Desktop.
$(function () {
$('#my_form').on('submit', function (e) {
// prevent browser from submitting the form
e.preventDefault();
var $form = $(this);
var formdata = (window.FormData) ? new FormData($form[0]) : null;
var data = (formdata !== null) ? formdata : $form.serialize();
$.ajax({
url: $form.attr('action'),
type: $form.attr('method'),
contentType: false, // mandatory for the upload
processData: false, // mandatory for the upload
dataType: 'json',
data: data,
success: function (response) {
// server responce
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment