promise封装

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>promise封装</title>
    <script src="https://cdn.staticfile.org/jquery/3.6.0/jquery.min.js"></script>
  </head>
  <style>
    body {
      background-image: url("https://static.runoob.com/images/mix/gradient2.png");
      background-repeat: repeat-x;
    }
    #box {
      width: 320px;
      height: 320px;
      margin: auto;
      margin-top: 10%;
      background: #fff;
      border: 2px solid rgba(183, 203, 225, 0.523);
    }
    .inp {
      width: 250px;
      height: 29px;
      margin-top: 20px;
      margin-left: 30px;
      border: 1px solid #ddd;
    }

    .nnb {
      width: 179px;
      height: 29px;
      margin-top: 20px;
      margin-left: 30px;
      border: 1px solid #ddd;
    }
    .nnc {
      width: 70px;
      height: 33px;
      position: absolute;
      margin-top: 20px;
      border: 1px solid #ddd;
      background-color: #fff;
    }
    .che {
      margin-left: 30px;
      margin-top: 20px;
    }
    #login {
      width: 260px;
      height: 35px;
      color: #fff;
      margin-top: 15px;
      margin-left: 30px;
      border: 1px solid #fff;
      background: #409eff;
    }
    div {
      width: 260px;
      height: 25px;
      border: 1px solid #fff;
      margin-left: 30px;
      margin-top: 20px;
    }
    span {
      font-size: 13px;
      position: absolute;
      margin-top: 17px;
    }
  </style>
  <body>
    <div id="box">
      <div>账号登录</div>
      <input type="text" class="inp" placeholder="用户名" id="username" />
      <input type="text" class="inp" placeholder="密码" id="password" />
      <input type="text" class="nnb" placeholder="验证码" id="vercode" />
      <button class="nnc"></button>
      <br />
      <input type="checkbox" class="che" /><span>记住密码</span>
      <button id="login">登&nbsp;录</button>
    </div>
  </body>
  <script type="module">
      $(function () {
        // 输入框默认值
        $("#username").val("11");
        $("#password").val("22");
        $("#login").click(function(){
        location.href = "././3.1网页.html";
        })
      });

    // 懒加载封装
    // 登录
     import { postlogin, getCode } from "./Flogin.js";
    postlogin().then((res) => {
      console.log(res);
      
    });
    // 验证码
    getCode().then((res) => {
      console.log(res);
      
    });
 
  </script>
</html>
Flogin.js文件

// 懒加载封装
// 登录
export function postlogin() {
  return new Promise((resolve, reject) => {
    $.ajax({
      url: "http://47.94.4.201/index.php/index/index/login",
      type: "POST",
      dataType: "json",
      data: {
        username: $("username").val(),
        password: $("password").val(),
        vercode: $("vercode").val(),
      },
      success: function (data) {
        console.log(data);
      },
    });
  });
}
// 验证码
export function getCode() {
  return new Promise((resolve, reject) => {
    $.ajax({
      url: "http://47.94.4.201/index.php/index/index/getcode",
      type: "GET",
      dataType: "json",
      success: function (data) {
        console.log(data);
        $(".nnc").html(data.msg);
      },
    });
    $(".nnc").click(function () {
      getCode();
    });
  });
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值