我尝试获取XML文档的内容,并使用ID GameReview将其添加到我的div元素中。
function getXML() //this is meant to retirieve the xml document.
{
var xmlrequest = new XMLHttpRequest();
xmlrequest.onreadystatechange =
function()
{
if (this.readyState==4 && this.status==200)
{
populateDIV(this);
}
};
xmlrequest.open("GET", "finalfantasy.xml", true);
xmlrequest.send();
}
function populateDIV(xml)
{
var finalfantasyReview = xml.responseXML;
var start;
var x = finalfantasyReview.getElementsByTagName("REVIEW");
start="<h2>"+x[0].getElementsByTagName("TITLE")[0].childNodes[0].nodeValue + "</h2>" +
"<h3>"+x[0].getElementsByTagName("OVERVIEW")[0].childNodes[0].nodeValue + "</h3>" +
"<p>"+x[0].getElementsByTagName("CONTENT")[0].childNodes[0].nodeValue +"</p>";
document.getElementById("GameReview").innerHtml = "";
document.getElementById("GameReview").innerHtml = start;
}
Below is my HTML the Elements in the div GameReview the contents should be replaced with the XML contents.
&#13;
<html>
<head>
<link rel="stylesheet" type="text/css" href="styleSheet.css">
<title> Logi's Blog</title>
</head>
<body>
<h1> Logi's Blog</h1>
<div id="nav">
<ul class="TopMenuContainer">
<li class="TopMenuList"><a href="">Games</a></li>
<li class="TopMenuList"><a href="">Cartoons</a></li>
<li class="TopMenuList"><a href="">TV Shows</a></li>
<li class="TopMenuList"><a href="">Anime</a></li>
</ul>
</div>
<h2 class="GamesTitle">Games</h2>
<div id="Container">
<div class="GamesListContainer">
<ul>
<li><button type="button" onclick="getXML()">Final Fantasy</button></li>
<li>Rachet and Clank</li>
</ul>
</div>
<div id="GameReview">
<h2>Game</h2>
<img src="images/getting_started_with_content_strategy.jpg" alt="content strategy" style="width:356px;height:200px;"/>
<h3>Overview<h3>
<p>This is where all the great content goes when you click on a review.</P>
<p id="GamePoopReview"></p>
</div>
<
</body>
<html>
&#13;
我不确定我做错了什么。
答案 0 :(得分:0)
我的函数PopulateDIV(xml)中的最后两行我忘了在对象.innerHTML中大写“HTML”。