• 欢迎光临~

ECM5 Fetch

开发技术 开发技术 2022-10-14 次浏览
<html>
<body>
    <button onclick="fetchImage()">Fetch</button>
    <button onclick="ajaxRequest()">Ajax</button>
    <button onclick="ajaxRequest2()">Ajax2</button>
    <script type="text/javascript">
        "use strick";
        const imgURL="https://images.pexels.com/photos/235767/pexels-photo-235767.jpeg?cs=srgb&dl=pexels-pixabay-235767.jpg&fm=jpg&w=640&h=427";
        let fetchImage= async()=>{
            var myImageResponse= await fetch(imgURL);
            console.log("Image response:n",myImageResponse.blob());
        }
        function ajaxRequest(){
            function reqListener(){
                console.log(this.response);
            }
            var xmlRequest=new XMLHttpRequest();
            xmlRequest.addEventListener("load",reqListener.bind(xmlRequest));
            xmlRequest.open("GET",imgURL);
            xmlRequest.send();
        }
        
        function ajaxRequest2(){
            
            var xmlRequest=new XMLHttpRequest();
            xmlRequest.open("GET",imgURL);
            xmlRequest.send();
            xmlRequest.onload=function(e){
                console.log(xmlRequest.response);
            }
        }
    </script>
</body>
</html>

 

程序员灯塔
转载请注明原文链接:ECM5 Fetch
喜欢 (0)
违法和不良信息举报电话:022-22558618 举报邮箱:dljd@tidljd.com