Skip to content

Instantly share code, notes, and snippets.

@thiagomarinho
Last active October 12, 2015 03:08
Show Gist options
  • Select an option

  • Save thiagomarinho/3962371 to your computer and use it in GitHub Desktop.

Select an option

Save thiagomarinho/3962371 to your computer and use it in GitHub Desktop.
Submit simples de formulário em ajax
$('#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