Bom dia amigo.
Uma vez eu fiz da seguinte forma... mas sei que deve haver forma mais simplificada... Mas o importante é que me atendeu bem na época... Veja:
<script type="text/javascript">
$(function() { // onload...do
$('#formContato').submit(function() {
var inputs = [];
$(':input', this).each(function() {
inputs.push(
this.name + '=' + escape(this.value));
})
// now if I join our inputs using '&' we'll have a query string
jQuery.ajax({
type: "POST",
data: inputs.join('&'),
url: "enviaForm.php",
timeout: 2000,
error: function(erro) {
//console.log("Failed to submit");
alert(erro);
},
/*success: function(r) {
alert(r);
}*/
success: function (r) {
alert(r);
$('#formContato').clearForm();
}
})
return false;
})
$.fn.clearForm = function() {
return this.each(function() {
var type = this.type, tag = this.tagName.toLowerCase();
if (tag == 'form')
return $(':input',this).clearForm();
if (type == 'text' || type == 'password' || tag == 'textarea')
this.value = '';
else if (type == 'checkbox' || type == 'radio')
this.checked = false;
else if (tag == 'select')
this.selectedIndex = -1;
});
};
})
</script>