Guest User

Untitled

a guest
Feb 8th, 2018
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.25 KB | None | 0 0
  1. $('document').ready(function () {
  2. var get_user = localStorage.getItem("username");
  3. var get_pass = localStorage.getItem("password");
  4. username = null;
  5. password = null;
  6.  
  7. if (get_user != null && get_pass != null) {
  8. alert("Tem user: " + get_user + " e password: " + get_pass);
  9. username = get_user;
  10. password = get_pass;
  11. }
  12.  
  13. $("#login").click(function (e) {
  14.  
  15. e.preventDefault();
  16. if (username == null || password == null) {
  17. var username = $("#username").val();
  18. var password = $("#password").val();
  19.  
  20. if (username.trim() == '' || password.trim() == '') {
  21. alert("Preenche o campo do utilizador e a password")
  22. return false;
  23. }
  24.  
  25. var formData = {
  26. 'username': username,
  27. 'password': password,
  28. };
  29. (data);
  30. $.ajax({
  31. type: 'POST',
  32. url: 'link',
  33. data: formData,
  34. dataType: 'JSON',
  35. success: function (data) {
  36. try {
  37. alert(data[0].username);
  38. alert(data[0].nif);
  39. alert(data[0].datanascimento);
  40. alert(data[0].email);
  41. alert(data[0].contacto);
  42. }
  43. catch (e) {
  44. alert("Utilizador ou password errados.");
  45. }
  46. }
  47. });
  48.  
  49. },
  50. );
  51. });
Add Comment
Please, Sign In to add comment