24 尚硅谷 AJAX Axios函数发送AJAX请求

24 尚硅谷 AJAX Axios函数发送AJAX请求

修改index.html代码

<!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>jquery 发送 ajax 请求</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css"
        integrity="sha384-HSMxcRTRxnN+Bdg0JdbxYKrThecOKuH5zCYotlSAcp1+c8xmyTe9GYg1l9a69psu" crossorigin="anonymous">
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>

</head>

<body>
    <button>GET</button>
    <button>POST</button>
    <button>AJAX</button>
    <SCript>
        const btns=document.querySelectorAll("button")
        axios.defaults.baseURL='http://192.168.1.254:8000'        
        btns[0].onclick=function(){
            axios.get('/axios-server',{
                params:{
                    id:100,
                    vip:7
                },
                headers:{
                    name:'atguigu',
                    age:20
                }
            }).then(value=>{
                console.log(value);
            })
        }
        btns[1].onclick=function(){
            axios.post('/axios-server',{
                    username:'admin',
                    password:'admin'
                },{
                params:{
                    id:100,
                    vip:7
                },
                headers:{
                    height:180,
                    weight:180
                }
            }).then(value=>{
                console.log(value);
            })
        }
        btns[2].onclick=function(){
            axios({
                method:'POST',
                url:'/axios-server',
                params:{
                    vip:10,
                    level:30
                },
                headers:{
                    a:100,
                    b:200
                },
                data:{
                    username:'admin',
                    password:'admin'
                }
            }).then(response=>{
                console.log(response);
                console.log(response.status);
                console.log(response.statusText);
                console.log(response.headers);
                console.log(response.data)
            })
        }
    </SCript>
</body>

</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值