Created
December 7, 2020 05:56
-
-
Save pteacher/bea1f47a42aafb966b972a28df36c037 to your computer and use it in GitHub Desktop.
API Example for COM19
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>API Example</title> | |
<script type="text/javascript"> | |
function get_dog() { | |
var xhttp = new XMLHttpRequest(); | |
xhttp.onreadystatechange = function() { | |
console.log(this.status); | |
if (this.readyState == 4 && this.status == 200) { | |
var dogimg = JSON.parse(this.responseText); | |
document.getElementById('dog').src = dogimg.message; | |
} | |
}; | |
xhttp.open("GET", "https://dog.ceo/dsf", true); | |
xhttp.send(); | |
} | |
get_dog(); | |
</script> | |
</head> | |
<body> | |
<div> | |
<img src="" id="dog" onclick="get_dog()" alt="press on image to load new dog"> | |
</div> | |
</body> | |
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<title>API Example</title> | |
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script> | |
<script type="text/javascript"> | |
function get_dog() { | |
$.get("https://dog.ceo/api/breeds/image/random", function(data, status){ | |
console.log(data); | |
$("#dog").attr("src", data.message); | |
}); | |
} | |
get_dog(); | |
</script> | |
</head> | |
<body> | |
<div> | |
<img src="" id="dog" onclick="get_dog()" alt="press on image to load new dog"> | |
</div> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment