Advertisement
Guest User

HTML

a guest
Dec 22nd, 2018
197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.42 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8" />
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <title>მთავარი</title>
  7. <meta name="viewport" content="width=device-width, initial-scale=1">
  8. <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"></script>
  9. <link rel="stylesheet" type="text/css" media="screen" href="simplmb.css" />
  10. <script src="simplmb.js"></script>
  11.  
  12. </head>
  13. <body>
  14. <form id="login" action="/login" method="POST">
  15. <label>
  16. Username:
  17. <input type="text" name="username" value="">
  18. </label>
  19.  
  20. <label>
  21. Password:
  22. <input type="password" name="password" value="" autocomplete="off">
  23. </label>
  24.  
  25. <button type="submit">Login</button>
  26. <br/>
  27. <div class="error"></div>
  28. </form>
  29.  
  30. <script type="text/javascript">
  31. $(function() {
  32.  
  33. var $loginForm = $('form#login');
  34.  
  35. // handle form submit event
  36. $loginForm.on('submit', function(e) {
  37. e.preventDefault(); // prevent browser doing default post
  38.  
  39. $.ajax({
  40. type: $loginForm.attr('method'), // get method from form tag
  41. url: $loginForm.attr('action'), // get action url from form tag
  42. contentType: 'application/json', // telling to server that will send json data
  43. data: JSON.stringify($loginForm.serializeArray()), // sending object with fields of form
  44.  
  45. // something went wrong
  46. error: function(xhr, textStatus, error) {
  47. try {
  48. var response = JSON.parse(xhr.responseText);
  49. if (response.message) { // if json response has message field
  50. $loginForm.find('.error:first').html(response.message);
  51. }
  52. }
  53. catch (error) { // tried to parse response string as json, but could not - then just put error string to div
  54. $loginForm.find('.error:first').html(xhr.responseText);
  55. }
  56. },
  57.  
  58. success: function(response) {
  59. if (response.redirectTo) {
  60. window.location.href = response.redirectTo;
  61. }
  62. }
  63. });
  64.  
  65. });
  66.  
  67. });
  68. </script>
  69. <a href="/reg">signup</a>
  70. </body>
  71. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement