• ajax请求


      1, 原生ajax-get请求
            function ajax_get(){
                var xhr = new XMLHttpRequest()
                xhr.open("get", "http://192.168.208.117:5000/login?account=a&password=b")
                xhr.send()
                xhr.onreadystatechange = function(){
                    if(xhr.readyState == 4){
                        console.log(1, xhr.responseText)
                    }
                }
            }
            ajax_get()

             2, 原生ajax-post请求
            function ajax_post(){
                var xhr = new XMLHttpRequest()
                xhr.open("post", "http://192.168.208.117:5000/login")
                xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
                xhr.send("account=a&password=b")
                xhr.onreadystatechange = function(){
                    if(xhr.readyState == 4){
                        console.log(2, JSON.parse(xhr.responseText))
                    }
                }
            }
            ajax_post()

             3, jquery封装的get请求
            $.get("http://192.168.208.117:5000/login", {
                account: 'a',
                password: 'b'
            }, data=>{
                console.log(3, data)
            })
            
             4, jquery封装的post请求
            $.post("http://192.168.208.117:5000/login", {
                account: 'a',
                password: 'b'
            }, data=>{
                console.log(4, data)
            })

             5, axios插件封装的get请求
            axios.get("http://192.168.208.117:5000/login",{
                params: { account: 'a', password: 'b'}
            }).then(res=>{
                console.log(5, res.data)
            })

             6, axios插件封装的post请求
            axios.post("http://192.168.208.117:5000/login",'account=a&password=b').then(res=>{
                console.log(6, res.data)
            })

             7, axios插件封装的post请求
            axios({
                method: "post",
                url: "http://192.168.208.117:5000/login",
                data: 'account=a&password=b'
            }).then(res=>{
                console.log(7, res.data)
            })

             8, fetch ES6新增的请求方式 , 默认get请求, 不建议使用fetch发post
            fetch("http://192.168.208.117:5000/login?account=a&password=b").then(res=>{
                res.json().then(data=>{
                    console.log(8, data)
                })
            })

  • 相关阅读:
    LeetCode:第305场周赛【总结】
    【Windows】局域网内共享文件夹的设置方法
    相机图像质量研究(23)常见问题总结:CMOS期间对成像的影响--紫晕
    移动软件开发实验三——视频播放小程序
    算法题:给定一个字符串,字符串中包含一些空格,将字符串中由空格隔开的单词反序,并反转每个字符的大小写。
    python基于django药房药品销售进销存管理系统
    Win11怎么彻底关闭粘滞键功能
    AR眼镜方案—单目光波导AR智能眼镜
    nginx修改成非root用户启动
    C++数据结构X篇_21_插入排序(稳定的排序)
  • 原文地址:https://blog.csdn.net/weixin_55711841/article/details/126300937