방금 JavaScript로 프로그래밍을 시작했고 위키피디아 API를 사용하여 내 자신의 위키 백과 페이지를 만들어야하지만 텍스트 상자에서 데이터를 가져 와서 결과를 표시하는 방법을 검색을 클릭하면 이해할 수 없습니다.디스플레이 위키 백과 검색 방법 은요?
<!DOCTYPE html>
<html>
<body>
<h1>Wikipedia</h1>
<div id="search1" />
<input type="text" name="search" /></b>
<button id="s1">search</button>
</div>
<p id="display"></p>
<script>
var xmlhttp = new XMLHttpRequest();
var url = "https://community-wikipedia.p.mashape.com/api.php" ;
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
myFunction(xmlhttp.responseText);
}
}
xmlhttp.open("GET", url, true);
var key = "oCdV3MjLj1mshtyIXwBVzBqRKtY9p1XJNiajsn1vsCETYVLwK3";
req.setRequestHeader("X-Mashape-Key", key);
xmlhttp.send();
function Function(response) {
var a = JSON.parse(response);
var i;
text = "";
for(i = 0; i < a.length; i++) {
text += a[i]+ "<br>";
}
document.getElementById("search1").addEventListener("click",displaysearch);
function displaysearch(){
//display search items here
}
}
</script>
</body>
</html>
그것은 아마 당신이 생략 한'displaysearch' 기능에있을 것입니다. –
예치하지만 내 html에 어떻게 연결합니까? –