Advertisement
Guest User

Untitled

a guest
Dec 13th, 2010
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.37 KB | None | 0 0
  1. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
  2. "http://www.w3.org/TR/html4/loose.dtd">
  3. <html>
  4. <head>
  5. <title>Ajax Login in php using jquery's fading effects</title>
  6. <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  7. <script src="/js/jquery.min.js" type="text/javascript" language="javascript"></script>
  8. <script language="javascript">
  9. // Developed by Roshan Bhattarai
  10. // Visit http://roshanbh.com.np for this script and more.
  11. // This notice MUST stay intact for legal use
  12.  
  13. $(document).ready(function()
  14. {
  15. $("#login_form").submit(function()
  16. {
  17. //remove all the class add the messagebox classes and start fading
  18. $("#msgbox").removeClass().addClass('messagebox').text('Validating....').fadeIn(1000);
  19. //check the username exists or not from ajax
  20. $.post("verify.php",{ username:$('#username').val(),password:$('#password').val(),remember:$('#remember').val(),rand:Math.random() } ,function(data)
  21. {
  22. if(data=='yes') //if correct login detail
  23. {
  24. $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
  25. {
  26. //add message and change the class of the box and start fading
  27. $(this).html('Logging in.....').addClass('messageboxok').fadeTo(900,1,
  28. function()
  29. {
  30. //redirect to secure page
  31. document.location='index.php';
  32. });
  33.  
  34. });
  35. }
  36. else
  37. {
  38. $("#msgbox").fadeTo(200,0.1,function() //start fading the messagebox
  39. {
  40. //add message and change the class of the box and start fading
  41. $(this).html('Your login detail sucks...').addClass('messageboxerror').fadeTo(900,1);
  42. });
  43. }
  44.  
  45. });
  46. return false; //not to post the form physically
  47. });
  48. //now call the ajax also focus move from
  49. $("#password").blur(function()
  50. {
  51. $("#login_form").trigger('submit');
  52. });
  53. });
  54. </script>
  55.  
  56. </head>
  57. <body>
  58.  
  59.  
  60. <br>
  61. <br>
  62. <style type="text/css">
  63. body {
  64. font-family:Verdana, Arial, Helvetica, sans-serif;
  65. font-size:11px;
  66. }
  67. .top {
  68. margin-bottom: 15px;
  69. }
  70. .buttondiv {
  71. margin-top: 10px;
  72. }
  73. .messagebox{
  74. position:absolute;
  75. width:100px;
  76. margin-left:30px;
  77. border:1px solid #c93;
  78. background:#ffc;
  79. padding:3px;
  80. }
  81. .messageboxok{
  82. position:absolute;
  83. width:auto;
  84. margin-left:30px;
  85. border:1px solid #349534;
  86. background:#C9FFCA;
  87. padding:3px;
  88. font-weight:bold;
  89. color:#008000;
  90.  
  91. }
  92. .messageboxerror{
  93. position:absolute;
  94. width:auto;
  95. margin-left:30px;
  96. border:1px solid #CC0000;
  97. background:#F7CBCA;
  98. padding:3px;
  99. font-weight:bold;
  100. color:#CC0000;
  101. }
  102.  
  103. </style>
  104. <form method="post" action="" id="login_form">
  105. <div align="center">
  106. <div class="top" > A fancy ajax login usin jQuery - <strong style="color:#FF0000">Use &quot;admin&quot; as username and &quot;roshan&quot; as password </strong></div>
  107.  
  108. <div >
  109. User Name : <input name="username" type="text" id="username" value="" maxlength="20" />
  110.  
  111. </div>
  112. <div style="margin-top:5px" >
  113. Password :
  114. &nbsp;&nbsp;
  115. <input name="password" type="password" id="password" value="" maxlength="20" />
  116.  
  117. </div>
  118. <input type="checkbox" name="remember" id="remember"/>
  119. <div class="buttondiv">
  120. <input name="Submit" type="submit" id="submit" value="Login" style="margin-left:-10px; height:23px" /> <span id="msgbox" style="display:none"></span>
  121.  
  122. </div>
  123.  
  124. </div>
  125. </form>
  126.  
  127.  
  128.  
  129.  
  130. </body>
  131. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement