Last active
October 12, 2015 03:08
-
-
Save thiagomarinho/3962371 to your computer and use it in GitHub Desktop.
Submit simples de formulário em ajax
This file contains hidden or 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
| $('#id-do-formulario').live('submit', function() { | |
| var form = $(this); | |
| if (form.data('submitting')) { | |
| return false; | |
| } | |
| form.data('submitting', true); | |
| var config = []; | |
| config['url'] = form.attr('action'); | |
| config['data'] = form.serialize(); | |
| config['type'] = 'post'; | |
| $.ajax(config) | |
| .complete(function(jqXHR, textStatus) { | |
| form.data('submitting', false); | |
| switch (textStatus) { | |
| case "error" : | |
| case "timeout" : | |
| case "abort" : | |
| case "parseerror" : | |
| // ERRO | |
| break; | |
| case "success" : | |
| case "notmodified" : | |
| // MANIPULE O jqXHR.responseText E VEJA SE DEU ERRO OU FOI OK | |
| break; | |
| } | |
| }); | |
| return false; | |
| }) | |
| .find('.bt-submit').live('click', function() { | |
| $(this).parents('form').trigger('submit'); | |
| return false; | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment