I'm just starting out with programming.
Currently, I am working on a project for school that involves displaying random dog images using an API. However, I keep encountering a 404 error even though I can see the URL changing and the dog breed updating in the console log. Instead of the expected photo, I only see a broken image icon on my HTML page.
Below is the code snippet I have:
let xhrdog = new XMLHttpRequest(); //AJAX request for dog photos from API
xhrdog.onreadystatechange = function() {
if (xhrdog.readyState === 4) {
if (xhrdog.status === 200) {
let ajdog = JSON.parse(xhrdog.responseText);
let image = document.createElement('img')
image.src = ajdog //xhrdog.responseText;
let dog = document.getElementById('dog')
dog.appendChild(image);
}
}
}
xhrdog.open('GET', 'https://dog.ceo/api/breeds/image/random');
xhrdog.send();
Any assistance or guidance on this issue would be highly appreciated.