zoukankan      html  css  js  c++  java
  • 封装一个ajax

    <!DOCTYPE html>

    <html lang="en">

      <head>

        <meta charset="UTF-8" />

        <meta name="viewport" content="width=device-width, initial-scale=1.0" />

        <meta http-equiv="X-UA-Compatible" content="ie=edge" />

        <title>Document</title>

      </head>

      <body>

    --------------------------------------------

        <script src="./node_modules/jquery/dist/jquery.js"></script>

        <script>

          function fetch(option) {

            const p = new Promise((resolve, reject) => {

              $.ajax({

                // 接口

                url: option.url,

                // 类型

                type: option.type || 'GET',

                // 数据 参数

                data: option.data || {},

                // 返回类型

                dataType: 'json',

                // 请求头

                header: option.header || {},

                // 成功回调

                success: resolve,

                // 失败回调

                error: reject

              })

            })

            return p

          }

    ----------------------------------------------------

          fetch({

            url:

              'http://localhost:8888/api/private/v1/login?username=admin&password=123456'

          }).then(res => {

            console.log(res)

          })

        </script>

      </body>

    </html>

  • 相关阅读:
    9月9号作业
    9月9号笔记
    jupyter的补充
    jupyter的使用
    9月6号作业
    编程语言的分类
    计算机组成
    计算机组成的补充
    面向对象基础
    9月2号作业
  • 原文地址:https://www.cnblogs.com/fmm030/p/12054268.html
Copyright © 2011-2022 走看看