axios的基础

一、axios的基本使用

1、axios 发送get请求 带参

<script src="https://cdn.bootcdn.net/ajax/libs/axios/0.21.1/axios.min.js"></script>
方式一:
axios({
      	 url: 'http://127.0.0.1/user/signout?id=1',
         method: 'get',
        }).then(res=>{
            console.log(res)
        })
方式二:
axios({
      	 url: 'http://127.0.0.1/user/signout',
         method: 'get',
         params:{
         	'id': 1 //url上拼接了?id=1
         } }).then(res=>{
            console.log(res)
        })
2、post方式发送请求[无参]

axios({
      	 url: 'http://127.0.0.1/user/signout',
         method: 'post',
        }).then(res=>{
            console.log(res)
        })    

原生ajax实现

var username = document.getElementById("txtUserName").value;
            var password = document.getElementById("txtpassword").value;
            {#console.log(username,password);#}
            {#console.log(params)#}
            $.ajax({
                type: "POST",
                dataType: "json",//服务器返回的数据类型
                contentType: "application/json",//post请求的信息格式
                url: "/user/signin",
                {#data: $('#form1').serialize(),#}
                data: JSON.stringify({
                        "username":username,
                        'password':password
                }),
                success: function (result) {
                    console.log(result);//在浏览器中打印服务端返回的数据(调试用)
                    if (result.resultCode == 200) {
                        alert("SUCCESS");
                    }
                    ;
                },
                error: function () {
                    alert("异常!");
                }
            });


 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值