Last active
December 16, 2015 10:29
-
-
Save gustavo-rodrigues-dev/5420907 to your computer and use it in GitHub Desktop.
Função Ajax completa, retornando um log personalizado de erro além de uma função a ser executada ao clicar ou invocar o reset;
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
$('form').on('submit', function(e){ | |
e.preventDefault(); | |
var self = this, | |
name = 'Salvar teste'; | |
$.ajax({ | |
url: this.action, | |
type: 'POST', | |
dataType: 'JSON', | |
data: $(this).serialize(), | |
cache: false, | |
success: function(res){ | |
if(res.status === 'TRA_OK'){ | |
/*seu código*/ | |
self.reset(); | |
} else { | |
} | |
}, | |
error: function(er){ | |
var args = this.data.split('&'), | |
parms = {}, | |
paramString =''; | |
for(var i = 0; i < args.length; i++) { | |
var bits = args[i].split('='); | |
parms[bits[0]] = bits[1]; | |
paramString += bits[0] +' : '+ bits[1] +'\n '; | |
} | |
console.error('Error executing the function '+name+'\n'+' Status server: '+er.status+ '\n URL:' + this.url +'\n Params: \n '+paramString); | |
} | |
}) | |
}); | |
$('form').on('reset', function(){ | |
$(this).hide(); | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment