Blogger Information
Blog 36
fans 1
comment 0
visits 28749
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
12月25日jQuery(AJAX请求)-九期线上班
WJF
Original
1043 people have browsed it


登陆页HTML


  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>用户登陆</title>
  6. <script src="jquery-3.4.1.min.js"></script>
  7. <script src="layer/layer.js"></script>
  8. <style>
  9. p{
  10. background-color: #0C9A9A;
  11. padding: 10px;
  12. margin: 10px 50px 0 50px;
  13. border-radius: 5px;
  14. }
  15. p input{
  16. border-radius: 5px;
  17. }
  18. button{
  19. background-color: #0a68b4;
  20. padding: 10px;
  21. margin: 10px 10px 0 50px;
  22. border-radius: 5px;
  23. }
  24. </style>
  25. </head>
  26. <form action="">
  27. <p>用户名:<input type="text" id="user" name="user"></p>
  28. <p>密码:<input type="password" id="pass" name="pass"></p>
  29. <button type="button" onclick="lpost()"> 登陆POST</button>
  30. <button type="button" onclick="lget()"> 登陆GET</button>
  31. </form>
  32. <script>
  33. function lpost() {
  34. var user = $.trim($('input[name="user"]').val());
  35. var pass = $.trim($('input[name="pass"]').val());
  36. $.post('/1225/lpost.php',$('form').serialize(),function(res){
  37. layer.alert(res.msg, {icon: res.icon});
  38. if(res.code==0){
  39. window.location.href = "/1225/user.html";
  40. }
  41. },'json');
  42. }
  43. function lget() {
  44. var user = $.trim($('input[name="user"]').val());
  45. var pass = $.trim($('input[name="pass"]').val());
  46. $.get('/1225/lget.php',{user:user,pass:pass},function (res) {
  47. layer.alert(res.msg, {icon: res.icon});
  48. if(res.code==0){
  49. window.location.href = "/1225/user.html";
  50. }
  51. },'json');
  52. }
  53. </script>
  54. </body>
  55. </html>

  1. <?php
  2. $user = $_POST['user'];
  3. $pass = $_POST['pass'];
  4. if ($user=='' || $pass==''){
  5. $data = json_encode(
  6. [
  7. 'code' => 400,
  8. 'msg' => '账号密码信息填写不完整!',
  9. 'icon' => 2
  10. ]
  11. );
  12. exit($data);
  13. }
  14. if ($user!='admin'){
  15. $data = json_encode(
  16. [
  17. 'code' => 1,
  18. 'msg' => '用户名错误',
  19. 'icon' => 5
  20. ]
  21. );
  22. exit($data);
  23. }
  24. if ($pass!='123456'){
  25. $data = json_encode(
  26. [
  27. 'code' => 2,
  28. 'msg' => '密码错误',
  29. 'icon' => 5
  30. ]
  31. );
  32. exit($data);
  33. }
  34. $data = json_encode(
  35. [
  36. 'code' => 0,
  37. 'msg' => '你好' . $user . '欢迎━(*`∀´*)ノ亻!',
  38. 'icon' => 1
  39. ]
  40. );
  41. exit($data);

  1. <?php
  2. $user = $_GET['user'];
  3. $pass = $_GET['pass'];
  4. if ($user=='' || $pass==''){
  5. $data = json_encode(
  6. [
  7. 'code' => 400,
  8. 'msg' => '账号密码信息填写不完整!',
  9. 'icon' => 2
  10. ]
  11. );
  12. exit($data);
  13. }
  14. if ($user!='1'){
  15. $data = json_encode(
  16. [
  17. 'code' => 1,
  18. 'msg' => '用户名错误',
  19. 'icon' => 5
  20. ]
  21. );
  22. exit($data);
  23. }
  24. if ($pass!='1'){
  25. $data = json_encode(
  26. [
  27. 'code' => 2,
  28. 'msg' => '密码错误',
  29. 'icon' => 5
  30. ]
  31. );
  32. exit($data);
  33. }
  34. $data = json_encode(
  35. [
  36. 'code' => 0,
  37. 'msg' => '你好' . $user . '欢迎━(*`∀´*)ノ亻!',
  38. 'icon' => 1
  39. ]
  40. );
  41. exit($data);
Correcting teacher:天蓬老师天蓬老师

Correction status:qualified

Teacher's comments:动画演示真好
Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post