Quote (carteblanche @ Mar 28 2015 11:05am)
that doesnt change the answer. that's how you read an xml document. if you have different tag names, then just parse it differently. getting the file didn't change.
Sorry if I seem ignorant but we just jumped into doing this and I am completely lost. This is the code we used in the lab, this is what I have to go off of.
Code
window.onload = initPage;
function initPage() {
var thumbs = document.getElementById("thumbnailPane").getElementsByTagName("img");
for (var i = 0; i < thumbs.length; i++) {
var image = thumbs[i];
image.onclick = function() {
var detailURL = "images/" + this.title + "-detail.jpg";
document.getElementById("itemDetail").src = detailURL;
getDetails(this.title);
}
}
}
function getDetails(itemName) {
request = createRequest();
if (request === null) {
alert("Unable to create request");
return;
}
var url= "getDetailsXML.php?ImageID=" + escape(itemName);
request.open("GET", url, true);
request.onreadystatechange = displayDetails;
request.send(null);
}
function displayDetails() {
if (request.readyState == 4) {
if (request.status == 200){
var detailDiv = document.getElementById("description");
for(var i = detailDiv.childNodes.length; i > 0; i--) {
detailDiv.removeChild(detailDiv.childNodes[i-1]);
}
var responseDoc = request.responseXML;
var description = responseDoc.getElementsByTagName("description")[0];
var descriptionText = description.firstChild.nodeValue;
var descriptionP = document.createElement("p");
descriptionP.appendChild(document.createTextNode("Description: " + descriptionText));
detailDiv.appendChild(descriptionP);
var price = responseDoc.getElementsByTagName("price")[0];
var priceText = price.firstChild.nodeValue;
var priceP = document.createElement("p");
priceP.appendChild(document.createTextNode("Price: $" + priceText));
detailDiv.appendChild(priceP);
var urlP = document.createElement("p");
var list = document.createElement("ul");
var urlElements = responseDoc.getElementsByTagName("url");
for(var i = 0; i < urlElements.length; i++){
var url = urlElements[i].firstChild.nodeValue;
var li = document.createElement("li");
var a = document.createElement("a");
a.setAttribute("href", url);
a.appendChild(document.createTextNode(url));
li.appendChild(a);
list.appendChild(li);
}
urlP.appendChild(list);
detailDiv.appendChild(urlP);
}
}
}