Advertisement
Guest User

Untitled

a guest
Oct 19th, 2016
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.48 KB | None | 0 0
  1. $(document).ready(function () {
  2. "use strict";
  3. $("#submit").click(function () {
  4.  
  5. var username = $("#myusername").val(), password = $("#mypassword").val();
  6.  
  7. if ((username === "") || (password === "")) {
  8. $("#message").html("<div class=\"alert alert-danger alert-dismissable\"><button type=\"button\" class=\"close\" data-dismiss=\"alert\" aria-hidden=\"true\">&times;</button>Please enter a username and a password</div>");
  9. } else {
  10. $.ajax({
  11. type: "POST",
  12. url: "checklogin.php",
  13. data: "myusername=" + username + "&mypassword=" + password,
  14. dataType: 'JSON',
  15. success: function (html) {
  16. //console.log(html.response + ' ' + html.username);
  17. if (html.response === 'true') {
  18. //location.assign("../index.php");
  19. location.reload();
  20. return html.username;
  21. } else {
  22. $("#message").html(html.response);
  23. }
  24. },
  25. error: function (textStatus, errorThrown) {
  26. console.log(textStatus);
  27. console.log(errorThrown);
  28. },
  29. beforeSend: function () {
  30. $("#message").html("<p class='text-center'><img src='images/ajax-loader.gif'></p>");
  31. }
  32. });
  33. }
  34. return false;
  35. });
  36. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement