insertAdjacentHTML
이 무엇이며 왜 내 스크립트가 작동하지 않는지 설명해 주시겠습니까?왜이 간단한 AJAX 스크립트가 작동하지 않습니까?
<!DOCTYPE html>
<html>
<head>
<title></title>
</head>
<body>
<div class="animal-info">
</div>
<button id="btn">Ae</button>
<script type="text/javascript">
var animalContainer = document.getElementById("animal-info");
var btn = document.getElementById('btn');
btn.addEventListener("click", function() {
var request = new XMLHttpRequest();
request.open('GET', 'https://learnwebcode.github.io/json-example/animals-1.json');
request.onload = function() {
var ourData = JSON.parse(request.responseText);
renderHTML(ourData);
};
request.send();
});
function renderHTML(data) {
animalContainer.insertAdjacentHTML('beforeend', 'testing 123');
};
</script>
</body>
</html>
id가 'animal-info' 인 요소가 없습니다. –
예상되는 동작과 실제로 발생하는 동작은 무엇입니까? 오류가 있습니까? "효과가 없다"는 것은 유용한 문제 설명이 아닙니다. –