Advertisement
Guest User

Untitled

a guest
Dec 16th, 2017
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.08 KB | None | 0 0
  1. function logInAjax(){
  2. var username = document.getElementById('login_username').value;
  3. var password = document.getElementById('login_password').value;
  4. var login = "username=" + username + "&password=" + password;
  5.  
  6. var usernameCheck = 0;
  7. var passwordCheck = 0;
  8.  
  9. if (username == "") {
  10. $("#error").html("" +
  11. "<div class='alert alert-warning alert-dismissible' role='alert'> " +
  12. "<button type='button' class='close' data-dismiss='alert' aria-label='Close'>" +
  13. "<p class='zmdi zmdi-close'</p>" +
  14. "</button>" +
  15. "<strong>" +
  16. "<i class='zmdi zmdi-alert-triangle'></i> Warning!" +
  17. "</strong>" +
  18. " Username cannot be Blank!" +
  19. "</div>");
  20. ("login");
  21. } else {
  22. usernameCheck = 1;
  23. }
  24.  
  25. if (password == "") {
  26. $("#error").html("" +
  27. "<div class='alert alert-warning alert-dismissible' role='alert'> " +
  28. "<button type='button' class='close' data-dismiss='alert' aria-label='Close'>" +
  29. "<p class='zmdi zmdi-close'</p>" +
  30. "</button>" +
  31. "<strong>" +
  32. "<i class='zmdi zmdi-alert-triangle'></i> Warning!" +
  33. "</strong>" +
  34. " Password cannot be blank." +
  35. "</div>");
  36. ("login");
  37. } else {
  38. passwordCheck = 1;
  39. }
  40.  
  41. if(usernameCheck == 1 && passwordCheck == 1){
  42. $.ajax({
  43. type: "POST",
  44. url: "userLogin.php",
  45. data: login,
  46. success: function(html){
  47. console.log(html);
  48. if(html == "Success"){
  49. $("#error").html("<div class='alert alert-success alert-dismissible' role='alert'> " +
  50. "<button type='button' class='close'>" +
  51. "<p class='zmdi zmdi-close'</p>" +
  52. "</button>" +
  53. "<strong>" +
  54. "<i class='zmdi zmdi-alert-triangle'></i> Success!" +
  55. "</strong>" +
  56. "Redirecting..." +
  57. "</div>"
  58.  
  59. );
  60. setTimeout(function() {
  61. window.location = "./index.php";
  62. }, 2000);
  63.  
  64. } else {
  65. $("#error").html("" +
  66. "<div class='alert alert-warning alert-dismissible' role='alert'> " +
  67. "<button type='button' class='close'>" +
  68. "<p class='zmdi zmdi-close'</p>" +
  69. "</button>" +
  70. "<strong>" +
  71. "<i class='zmdi zmdi-alert-triangle'></i> Warning!" +
  72. "</strong>" +
  73. "<br>" +
  74. "Incorrect username and password." +
  75. "</br>" +
  76. "</div>"
  77. );
  78. };
  79. },
  80. beforeSend:function(){
  81. $("#error").html("Logging In");
  82. }
  83. });
  84. return false;
  85. } else {
  86. $("#error").html("" +
  87. "<div class='alert alert-warning alert-dismissible' role='alert'> " +
  88. "<button type='button' class='close' data-dismiss='alert' aria-label='Close'>" +
  89. "<p class='zmdi zmdi-close'</p>" +
  90. "</button>" +
  91. "<strong>" +
  92. "<i class='zmdi zmdi-alert-triangle'></i> Warning!" +
  93. "</strong>" +
  94. "Please fill out the necessary information." +
  95. "</div>");
  96. ("login");
  97. }
  98. }
  99.  
  100. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement