Created
September 10, 2013 00:07
-
-
Save fabriciosanchez/6503249 to your computer and use it in GitHub Desktop.
Javascript que serializa o formulário de forma assíncrona com jQuery.
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
<script src="http://code.jquery.com/jquery-1.9.1.js"></script> | |
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jquery.validate/1.11.1/jquery.validate.js" ></script> | |
<script type="text/javascript"> | |
$(document).ready(function () { | |
$("#formulario").validate({ | |
rules: { | |
Nome: { | |
required: true | |
}, | |
Email: { | |
required: true, | |
email: true | |
} | |
}, | |
messages: { | |
Nome: "Usuário obrigatório.", | |
Email: { | |
required: "Email obrigatório.", | |
email: "Por favor, informe um e-mail válido." | |
} | |
}, | |
submitHandler: function () { | |
$.ajax({ | |
type: "get", | |
url: "/Serializacao/ProcessaFormulario", | |
data: $("#formulario").serialize(), | |
success: function (data) { | |
if (data.OK) | |
{ | |
$("#Resultado").text(data.Nome + " - " + data.Email); | |
} | |
else | |
{ | |
$("#Resultado").text("Falhou!"); | |
} | |
} | |
}); | |
return false; | |
} | |
}); | |
}); | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment