Skip to content

Instantly share code, notes, and snippets.

@heat
Created January 10, 2014 14:03
Show Gist options
  • Save heat/8352625 to your computer and use it in GitHub Desktop.
Save heat/8352625 to your computer and use it in GitHub Desktop.
como enviar um post por ajax tratando o retorno. Evitando assim o redirecioanmento do browser
$('#formid').on('submit', function(event) {
event.preventDefault();
var $form = $(this);
var url = $form.attr('action');
$.post( url, $form.serialize())
.done( function(data) {
//trata caso tenha voltado um codigo 200
})
.fail( function( ajx, sc) {
alert("problemas durante a requisição.\n" + sc); });
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment