Ajax请求的方式

1.第三种请求json文件的方法

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="js/axios.min.js"></script>
    <script>
        //第四种Ajax请求的方式 fetch
        axios.get("./00 data.json",{
            //Headers:{ 请求头,进行伪装

            //}
            params:{ //params参数
                id:1001
            }
        })
        .then(function(response){
            console.log(response.data);//data请求数据
        })
        .catch(function(error){
            console.log(error);
        })
    </script>
</head>
<body>
    
</body>
</html>

Ajax请求的方式

 

 

 

2.第四种请求json文件的方法

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script>
        //plain纯文本
        //第三种Ajax请求的方式 fetch
        fetch("./00 data.json",{})//{}参数可不写
           //固定格式
           .then(function(response){ //response
               //resolve 成功
               console.log(response);
                return response.json();
           })
           //获取数据
           .then(function(data){//返回的是数据
                console.log(data);
           })
           .catch(function(){//出错
               //reject 失败
           });
    </script>
</head>
<body>
    
</body>
</html>

Ajax请求的方式

 

上一篇:ajax请求接口与postman请求接口格式问题


下一篇:狂神-AJAX