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