Advertisement
Bruno

Ajax e formulário HTML

Dec 28th, 2012
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <script src="http://code.jquery.com/jquery-1.7.1.min.js"></script>
  2.  
  3. <script>
  4. function sendData(login, pass) {
  5.     $.ajax({
  6.         url: "pagina.php?"+$("form").serialize(),  
  7.         success: function(data) {
  8.             receiveData(data);
  9.         }
  10.     });
  11.     return true;
  12. }
  13. function receiveData(resposta) {
  14.     alert(resposta);
  15.     document.getElementById("user").value = '';// limpa o campo
  16.     document.getElementById("pass").value = '';// limpa o campo
  17.     document.formLogin.usuario.focus();// seta o focus
  18.     return true;
  19. }
  20. </script>
  21.  
  22. <form action="javascript:sendData();" method="post" name="formLogin" enctype="multipart/form-data">
  23.     <span>User:<br/></span>
  24.     <input type="text" id="user" name="user"/>
  25.    
  26.     <br/><!-- space -->
  27.    
  28.     <span>Pass:<br/></span>
  29.     <input type="password" id="pass" name="pass"/>
  30.    
  31.     <br/><!-- space -->
  32.    
  33.     <input type="submit" name="enter" value="Enviar"/>
  34. </form>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement