Skip to content

Instantly share code, notes, and snippets.

@marcojetson
Created June 16, 2015 08:56
Show Gist options
  • Save marcojetson/b5c3ce73a58ad89cdd64 to your computer and use it in GitHub Desktop.
Save marcojetson/b5c3ce73a58ad89cdd64 to your computer and use it in GitHub Desktop.
convert forms to ajax forms
$('body').on('submit', 'form.ajax', function () {
var form = $(this);
$.ajax({
type: form.attr('method') || 'GET',
url: form.attr('action') || location.href,
data: form.serialize(),
success: function (data, textStatus, jqXHR) {
form.trigger('success', [data, textStatus, jqXHR]);
},
error: function (jqXHR, textStatus, errorThrown) {
form.trigger('error', [jqXHR, textStatus, errorThrown]);
},
complete: function (jqXHR, textStatus) {
form.trigger('complete', [jqXHR, textStatus]);
}
});
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment