0
我正在學習API,並且是該流程的初學者,任何幫助都很有價值。以HTML格式顯示API響應
我已經設法得到數據即時尋找作爲XML響應,並有console.logged它在鉻。我不確定如何實際訪問此#document我在控制檯中看到看到下面的代碼和控制檯打印
<!doctype html>
<html>
<head>
<script>
window.onload = function() {
var xhr = new XMLHttpRequest();
xhr.open("GET","http://api.openweathermap.org/data/2.5/weather?lat=35&lon=139&mode=xml&APPID=92cc96ecfe265f251d814b66592a7848",false);
xhr.send();
console.log(xhr.status);
console.log(xhr.statusText);
console.log(xhr.responseXML);
var response = xhr.responseXML;
var xmlString = (new XMLSerializer()).serializeToString(response);
if(xhr.status == 200){
document.getElementById("document").innerHTML = xmlString;
}
}
</script>
<meta charset="UTF-8">
<title>Weather API Test</title>
</head>
<body id="body">
<div id="document"></div>
</body>
</html>
和控制檯顯示:
200
OK
#document
all of the XML is contained in here that I need to access and display
我搜索了整個週末,我找不到我能夠理解的解決方案。
在此先感謝
爲什麼下跌投票? – anthonytherockjohnson