JavaScript-ajax,axios

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>ajax</title>
</head>
<body>
<input type="button" value="获取数据" onclick="getData()">
<div id="div1"></div>
</body>
<script>//
    function getData() {
        //创建XMLHttpRequest对象,用于和服务器交换数据
        var xmlHttpRequest = new XMLHttpRequest();
        //发送异步请求
        xmlHttpRequest.open("get", "http://www.baidu.com");
        xmlHttpRequest.send();//发送请求
        //获取服务响应数据
        xmlHttpRequest.onreadystatechange = function () {
            if (xmlHttpRequest.readyState == 4 && xmlHttpRequest.status == 200) {
                document.getElementById('div1').innerHTML = xmlHttpRequest.responseText;
            }
        }
    }
</script>
</html>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>axios</title>
    <script src="../vue/axios.js"></script>
</head>
<body>
<input type="button" value="get请求" onclick="get()">
<input type="button" value="post请求" onclick="post()">
</body>
<script>
    function get() {
        axios({
            method:"get",
            url:"http://yapi.smart-xwork.cn/mock/169327/emp/list"
        }).then(result=>{
            console.log(result.data)
        })
    }
    function post() {
        axios({
            method:"post",
            url:"http://yapi.smart-xwork.cn/mock/169327/emp/deleteById",
            data:"id=1"
        }).then(result=>{
            console.log(result.data)
        })
    }
</script>
</html>
<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>axios表格</title>
<!--    <script src="../vue/axios.js"></script>-->
<!--    <script src="../vue/vue.js"></script>-->
    <script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>
</head>
<body>
<div id="app">
    <table>
        <tr>
            <th>编号</th>
            <th>姓名</th>
            <th>图像</th>
            <th>性别</th>
            <th>职位</th>
            <th>入职时间</th>
            <th>最后操作时间</th>
        </tr>
        <tr  v-for="(item,index) in emps">
            <td>{{index+1}}</td>
            <td>{{item.name}}</td>
            <td><img v-bind:src="item.url"></td>
            <td v-if="item.gender==1"></td>
            <td v-if="item.gender==2"></td>
            <td>{{item.job}}</td>

            <td>{{item.entrydate}}</td>
            <td>{{item.updatetime}}</td>
        </tr>
    </table>
</div>
<script>
    new Vue({
        el: "#app",
        data: {
            emps: [ ]
        },
        mounted()
        {
            axios.get("http://yapi.smart-xwork.cn/mock/169327/emp/list").then(result => {
                this.emps = result.data.data;
            })
        }
    });
</script>
</body>
</html>
<!DOCTYPE html>
<html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="UTF-8">
    <title>axios表格</title>
    <script src="../vue/axios.js"></script>
    <script src="../vue/vue.js"></script>
    <!--<script src="https://cdn.jsdelivr.net/npm/vue@2.6.14/dist/vue.js"></script>
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>-->
</head>
<body>
<div id="app">
    <table>
        <tr>
            <th>编号</th>
            <th>姓名</th>
            <th>图像</th>
            <th>性别</th>
            <th>职位</th>
            <th>入职时间</th>
            <th>最后操作时间</th>
        </tr>
        <tr  v-for="(item,index) in emps">
            <td>{{index+1}}</td>
            <td>{{item.name}}</td>
            <td><img v-bind:src="item.url"></td>
            <td v-if="item.gender==1"></td>
            <td v-if="item.gender==2"></td>
            <td>{{item.job}}</td>

            <td>{{item.entrydate}}</td>
            <td>{{item.updatetime}}</td>
        </tr>
    </table>
</div>
<script>
    new Vue({
        el: "#app",
        data: {
            emps: [ ]
        },
        mounted()
        {
            axios.get("http://yapi.smart-xwork.cn/mock/169327/emp/list").then(result => {
                this.emps = result.data.data;
            })
        }
    });
</script>
</body>
</html>
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

麻烦放收发室,谢谢

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值