Advertisement
Guest User

Untitled

a guest
Feb 13th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.38 KB | None | 0 0
  1. <?php
  2.  
  3. $f = '';
  4.  
  5. $data = array();
  6.  
  7. if (isset($_GET['f'])){
  8. $f = $_GET['f'];
  9. }
  10.  
  11. if ($f == 'test'){
  12. $data = array(
  13. "status" => 900
  14. );
  15.  
  16. header("Content-type: application/json");
  17. echo json_encode($data);
  18. exit();
  19. }
  20. ?>
  21.  
  22.  
  23.  
  24.  
  25.  
  26.  
  27.  
  28.  
  29.  
  30. <!doctype html>
  31. <html lang="de">
  32. <head>
  33. <meta charset="utf-8">
  34. <meta name="viewport" content="width=device-width, initial-scale=1.0">
  35. <style>
  36. .background{ width: 300px; height: 350px; background-color: white; position: absolute; left: 50%; top: 50%; margin-top: -175px; margin-left: -150px; border-radius: 50px; }
  37. .heading{text-align: center; font-size: 20pt;}
  38. .input{ width: 95%; border: none; margin-top: 20px; height: 38px; margin-left: 2.5%; }
  39. .loginBtn{ width: 100%; position: relative; height: 40px; margin-top: 15px; }
  40. </style>
  41. <script src="../imports/jQuery.js"></script>
  42. </head>
  43. <body>
  44. <div class="background">
  45. <div class="heading">Login</div>
  46. <form>
  47. <input class="input" type="text" id="username" placeholder="Username" />
  48. <input class="input" type="password" id="password" placeholder="Password" />
  49. <button type="button" class="loginBtn" onclick="tryLogin()" id="loginBtn">Login</button>
  50.  
  51.  
  52. </form>
  53. <div id="msg"></div>
  54. </div>
  55. </body>
  56. </html>
  57.  
  58. <script>
  59. var username = "";
  60. var password = "";
  61.  
  62. function tryLogin() {
  63.  
  64. username = $("#username").val();
  65. password = $("#password").val();
  66.  
  67. if (username != "") {
  68. if (password != "") {
  69. test(username, password);
  70. } else {
  71. $("#msg").html("Bitte gib ein Password ein.");
  72. }
  73. } else {
  74. $("#msg").html("Bitte gib einen Usernamen ein.");
  75. }
  76. }
  77.  
  78. function test(username, password) {
  79. jQuery.ajax({
  80. url: 'http://localhost/request.php?f=test',
  81. type: 'POST',
  82. data: { username: username, password: password },
  83. dataType: 'json',
  84. success: function (data) {
  85. console.log(data);
  86. },
  87. error: function (jqXHR, textStatus, errorThrown) {
  88. console.log(jqXHR);
  89. console.log(textStatus);
  90. console.log(errorThrown);
  91. }
  92. })
  93. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement