美文网首页
请求接口方法合集

请求接口方法合集

作者: 聆风者 | 来源:发表于2022-09-22 16:48 被阅读0次

 原生ajax

        get

        let xhr = new XMLHttpRequest()

        xhr.open('get', 'http://www.liulongbin.top:3006/api/getbooks?id=1')

        xhr.send()

        xhr.onreadystatechange = function () {

            if (this.readyState === 4 && this.status === 200) {

                console.log(this.responseText)

            }

        }

        post

        let xht = new XMLHttpRequest()

        xht.open('post', 'http://47.100.227.25:3000/users/register')

        xht.setRequestHeader('content-type', "application/x-www-form-urlencoded")

        xht.send('username=111&userpwd=111')

        xht.onreadystatechange = function () {

            if (this.readyState === 4 && this.status === 200) {

                console.log(this.responseText)

            }

        }

jQuery中的ajax

        $.ajax({

            url: 'http://www.liulongbin.top:3006/api/getbooks?id=1',

            method: 'GET',

            // data: 'a=100&b=200',

            data: { a: 100, b: 200 },

            dataType: 'json',

            success(res) {

                console.log(res)

                console.log(this)

            },

            error(xhr, info, err) {

            },

            timeout: 1000, // 1s 没有接收到响应就会取消本次请求

        })

        get请求

        $.get('http://www.liulongbin.top:3006/api/getbooks',{id:1},res=>{

            console.log(res)

        })

         post请求

        $.post('http://47.100.227.25:3000/users/register','username=111&userpwd=111',res=>{

            console.log(res)

        })

 promise-ajax

        new Promise((resolve, reject) => {

            $.get('http://www.liulongbin.top:3006/api/getbooks?id=1',res=>{

                resolve(res)

            })

        }).then(res=>{

            console.log(res)

        })

    axios

           get

        axios.get('http://www.liulongbin.top:3006/api/getbooks',{

            params:{

                id:1

            }

        })

        .then(res=>{

            console.log(res)

        })

        post

        axios.post('http://47.100.227.25:3000/users/register','username=111&userpwd=111',{

            username:111,

            userpwd:111

        })

        .then(res=>{

            console.log(res)

        })

async - axios

        async function fn(){

             let res = await axios.get('http://www.liulongbin.top:3006/api/getbooks?id=1')

             console.log(res)

        }

        fn()

```

相关文章

  • TSS对接api

    认证 接口列表 认证接口详情 login 请求方法 POST 请求参数 返回结果 register 请求方法 PO...

  • 测试面试题二

    接口文档包含哪些内容? 接口的协议(http https),协议的版本 接口的功能 请求方法:请求方法,get和p...

  • API是什么?

    API文档 API接口一般分为接口描述、接口地址、请求方法、请求参数、相应内容、错误代码、实例几个部分。 1、接口...

  • Retrofit 基础篇

    一、Retrofit 网络请求接口的注解类型:网络请求方法、标记类、网络请求参数 (1)网络请求方法 (2)标记类...

  • 接口规范

    统一接口命名 /接口版本/模块/对象/行为 统一请求头 请求参数和返回参数统一使用驼峰命名法 接口请求 时间,方法...

  • 如何看懂API接口文档?

    API接口一般分为接口描述、接口地址、请求方法、请求参数、相应内容、错误代码、实例几个部分。 1、接口描述 简单描...

  • 2016-08-18 短信接口、ajax请求

    短信接口、ajax请求 ajax请求 $.ajax()方法详解 url type timeout: async: ...

  • 2018-10-31 接口测试

    接口规范 规范类型swagger接口规范内容1.协议2.请求方法3.路径4.请求请求头 格式:utf-8请求正文...

  • OAuth2生成token代码备忘

    一、登录接口(用户名+密码) 1、前端请求auth服务 2、请求数据 3、Controller方法 二、授权接口调...

  • postman之接口测试content-type头域

    接口测试核心四要素:请求方法、请求协议、头域、请求头。请求方式:Get请求、Post请求传参:表单提交、请求体提交...

网友评论

      本文标题:请求接口方法合集

      本文链接:https://www.haomeiwen.com/subject/xeunortx.html