LOADING...

Preview

Pen ID
Unlock Campus Themeforest adv

 

Code

Dog?!

CSS
img {
  height: 200px;
}
.container {
  display: flex;
  flex-direction: column;
  align-items: center;
}

button {
  margin: 20px;
}
JS
var btn = document.querySelector("#button");

btn.addEventListener("click", function(){
  updateDogImageFromAPI();
});

function updateDogImageFromAPI() {
  var img = document.querySelector("#photo");
  
  var XHR = new XMLHttpRequest();
  
  XHR.onreadystatechange = function() {
    if (XHR.readyState == 4 && XHR.status == 200) {
      var resp = JSON.parse(XHR.responseText);
      img.src = resp.message;
    }
  }
  
  XHR.open("GET","https://dog.ceo/api/breeds/image/random");
  XHR.send();
};

var intervalId = setInterval(function(){
  updateDogImageFromAPI();
}, 3000);
Term
Fri, 01/12/2018 - 16:46

Related Codes

Pen ID
Pen ID
Pen ID
Square Adv