Created
June 16, 2015 08:56
-
-
Save marcojetson/b5c3ce73a58ad89cdd64 to your computer and use it in GitHub Desktop.
convert forms to ajax forms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('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