Advertisement
Guest User

Untitled

a guest
Feb 8th, 2019
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. <html>
  2. <body>
  3.  
  4. <form name="modulo">
  5. <p>Username <input type="text" name="user" id="user"></p>
  6. <p>Password <input type="password" name="pass" id="pass"></p>
  7. <input type="button" id="bottone" value="Accedi">
  8. </form>
  9.  
  10. <div id="risultato"></div>
  11.  
  12.  
  13.  
  14.  
  15. <script src="http://code.jquery.com/jquery-latest.js"></script>
  16.  
  17.  
  18.  
  19. <script type="text/javascript">
  20. $(document).ready(function() {
  21. $("#bottone").click(function(){ //Pigiando il bottone del form sopra si avvia ajax
  22. var user = $("#user").val(); //Salviamo come variabile il parametro #user e #pass
  23. var pass = $("#pass").val();
  24. $.ajax({
  25. type: "POST",
  26. url: "verificaCredenziali.php", //url in cui scambiare i dati
  27. data: "user=" + user + "&pass=" + pass, //inviamo i seguenti dati
  28. dataType: "",
  29. success: function(risposta)
  30. {
  31. if(risposta=="correct")
  32. $(location).attr('href','./benvenuto');
  33. else
  34. alert("Le tue credenziali non sono corrette");
  35.  
  36. //$("div#risultato").html(risposta); //html modificherà il tag risultato con il valore risposta.
  37. },
  38. error: function() //in caso di errore va alert
  39. {
  40. alert("Chiamata fallita, si prega di riprovare...");
  41. }
  42. });
  43. });
  44. });
  45. </script>
  46.  
  47.  
  48.  
  49. </body>
  50. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement