Advertisement
Guest User

Script.js

a guest
Feb 16th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $(document).ready(function() {
  2.   $(".authentication").hide();
  3.   $(".message").hide();
  4.  
  5.   $.ajax({
  6.     url: "chat.php",
  7.     cache: false,
  8.     type: "POST",
  9.     data: { get: true },
  10.     success: function(data) {
  11.       $(".messages").html(data);
  12.     }
  13.   });
  14.  
  15.   $("#login").click(function() {
  16.     $.ajax({
  17.       url: "authentication.php",
  18.       cache: false,
  19.       type: "POST",
  20.       data: { clicked: 0, username: $(".login-username").val(), password: $(".login-password").val() },
  21.       success: function(data) {
  22.         if (!data.includes("try again")) {
  23.           location.reload();
  24.         } else {
  25.           $(".message").html(data);
  26.           $(".message").slideDown();
  27.         }
  28.       }
  29.     });
  30.   });
  31.  
  32.   $("#register").click(function() {
  33.     $.ajax({
  34.       url: "authentication.php",
  35.       cache: false,
  36.       type: "POST",
  37.       data: { clicked: 1, username: $(".register-username").val(), password: $(".register-password").val(), confirmPassword: $(".confirm-password").val() },
  38.       success: function(data) {
  39.         if (data.includes("Success")) {
  40.           location.reload();
  41.         } else {
  42.           $(".message").html(data);
  43.           $(".message").slideDown();
  44.         }
  45.       }
  46.     });
  47.   });
  48.  
  49.   $("#send").click(function() {
  50.     $.ajax({
  51.       url: "chat.php",
  52.       cache: false,
  53.       type: "POST",
  54.       data: { get: false, message: $("#message").val() },
  55.       success: function(data) {
  56.         if (data.includes("login")) {
  57.           $(".authentication").slideDown();
  58.         }
  59.         $(".messages").html(data);
  60.       }
  61.     });
  62.   });
  63. });
  64.  
  65. $("#logout").click(function() {
  66.   $.ajax({
  67.     url: "authentication.php",
  68.     cache: false,
  69.     type: "POST",
  70.     data: { clicked: 2 },
  71.     success: function(data) {
  72.       location.reload();
  73.     }
  74.   });
  75. });
  76.  
  77. $("#authentication").click(function() {
  78.   $(".authentication").slideToggle();
  79. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement