Advertisement
Guest User

Untitled

a guest
Apr 20th, 2014
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.91 KB | None | 0 0
  1. <script type="text/javascript">
  2. $(document).ready(function(){
  3. $('#loginSubmit').click(function () {
  4. //start the ajax
  5. var f = $("#loginForm");
  6. request = $.ajax({
  7. //this is the php file that processes the data
  8. url: "app/index.php",
  9. type: "POST",
  10. data: f.serialize(),
  11. dataType:"json",
  12. cache: false
  13. });
  14. request.done(function (response, textStatus, jqXHR){
  15. // log a message to the console
  16. console.log("Hooray, it worked!");
  17. // callback handler that will be called on failure
  18. request.fail(function (jqXHR, textStatus, errorThrown){
  19. // log the error to the console
  20. console.error(
  21. "The following error occured: "+
  22. textStatus, errorThrown
  23. );
  24. alert("fail")
  25. });
  26. // callback handler that will be called regardless
  27. // if the request failed or succeeded
  28. request.always(function () {
  29. // reenable the inputs
  30. alert("ok")
  31. });
  32. });
  33. });
  34. });
  35. </script>
  36.  
  37. <form id="loginForm" action="" method="post" name="loginForm">
  38. <h1>Login Form</h1>
  39. <div>
  40. <input type="text" placeholder="Email" required="" id="email" name="userEmail" />
  41. </div>
  42. <div>
  43. <input type="password" placeholder="Password" required="" id="userPassword" name="userPassword" />
  44. </div>
  45. <div>
  46. <input type="hidden" value="login" id="tag" name="tag" />
  47. <input type="submit" value="Log in" id="loginSubmit" name="loginSubmit" />
  48. <a href="#">Lost your password?</a>
  49. </div>
  50. </form>
  51.  
  52. $('#loginform').submit(function(event){
  53. event.preventDefault();
  54.  
  55. $.ajax({
  56. //this is the php file that processes the data
  57. url: $(this).attr("action"),
  58. type: "POST",
  59. data: $(this).serialize(),
  60. dataType:"json",
  61. cache: false
  62. })
  63. .done(function (response, textStatus, jqXHR){
  64. // log a message to the console
  65. console.log("Hooray, it worked!");
  66. })
  67. .fail(function (jqXHR, textStatus, errorThrown){
  68. // log the error to the console
  69. console.error(
  70. "The following error occured: " + textStatus,
  71. errorThrown
  72. );
  73. alert("fail");
  74. })
  75. .always(function () {
  76. // callback handler that will be called regardless
  77. // if the request failed or succeeded
  78. // reenable the inputs
  79. alert("ok");
  80. });
  81. });
  82.  
  83. $('#loginSubmit').click(function (e) {
  84. e.preventDefault();
  85. ...
  86. });
  87.  
  88. $('#loginSubmit').click(function () {
  89. ...
  90. return false;
  91. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement