0

我一直在尝试对giflayer进行 API 调用以下载 .gif 文件。我似乎犯了一些简单的错误。无论我尝试什么,请求都不会超过 readyState 1

    function sendGifAPI(){
      //called when the user presses the "creategif" button
      makeRequest(function(result){
        document.getElementById("readystate").innerHTML = result;
      });
    }

    function makeRequest(handleResponse){
      var req = new XMLHttpRequest();
      var headerss = req.getAllResponseHeaders();
      req.onreadystatechange = function() {
        if(req.readyState === 1){
          document.getElementById("readystate").innerHTML = "1";
        }
        if(req.readyState === 2){
          document.getElementById("readystate").innerHTML = "2";
        }
        if(req.readyState === 3){
          document.getElementById("readystate").innerHTML = "3";
        }
        if(req.readyState === 4){
          if(req.status === 200){
            document.getElementById("readystate").innerHTML = "4";
            handleResponse(req.response);
          }
        }
      };
      req.open("GET", "http://apilayer.net/api/capture?access_key=8b29be98c80dbc3e7f3b04b03b3b2cd5&url=https://www.youtube.com/watch?v=3W6hZR29l5o&start=10&end=15");
      req.send();
    }
<!DOCTYPE html>
<html>
  <body>
    <p id="readystate"></p>

    <input type="button" onclick="sendGifAPI()" value="Create Gif">
    
    <img id="gifloader" />
  </body>
</html>

4

0 回答 0