fetch和Ajax

<script>
        /*
            then response
            then data
        */
        fetch('./data.json')
            //固定写法
            .then(function (response) {
                // resolve
                // console.log(response);
                return response.json();
            })
            //参数
            .then(function(data){
                console.log(data);
            })
            .then(function () {
                // reject
            });
    </script>
<script src="js/axios.min.js"></script>
    <script>
        /*
            参数  params
            数据  .data
        */
        axios.get("./data.json",{
            params:{
                id:1001
            }
        })
        .then(function(response){
            console.log(response.data)
        })
        .catch(function(err){
            console.log(err);
        })
    </script>
posted @ 2021-11-23 20:24  与神明画过押  阅读(20)  评论(0)    收藏  举报