Forum Moderators: open
Any thoughts?
You are my hero for getting back to me. The url of the xml doc is within the same folder as the html doc that's calling it. It's a relative link that is just the following :
http.open('get', 'beerdescriptions.xml', true)
Is that the issue you think? Any thoughts on a solution?
Also, can you help me with the native test for later IE? here's my full script:
<script type="text/javascript">
function fix_external_links() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i = 0; i < anchors.length; i++) {
var anchor = anchors[i];
if (anchor.getAttribute("rel") && anchor.getAttribute("rel") == "external") {
anchor.target = "_blank";
}
}
}
window.onload = fix_external_links;
function createRequestObject() {
var xmlHttp;
try {
// Firefox, Opera 8.0+, Safari
xmlHttp = new XMLHttpRequest();
}
catch (e) {
// Internet Explorer
try {
xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) {
alert("Your browser does not support AJAX!");
return false;
}
}
}
return xmlHttp;
}
var http = createRequestObject();
function sndReq() {
var that = this; // The link that triggered this event
// The callback function for the http request
http.open('get', 'beerdescriptions.xml', true)
http.send(null);
http.onreadystatechange = function () {
var found = 0
if (http.readyState == 4) {
// that refers to the link
var test = that.innerHTML
var response = http.responseXML.documentElement
var set = response.getElementsByTagName("SET")
beerslicestart = test.lastIndexOf('<');
beersliceend = test.lastIndexOf('">') + 2;
beerslice = test.substring(beersliceend,beerslicestart);
brewersliceend = test.lastIndexOf('</span> ');
brewerslicestart = test.lastIndexOf('nd">') + 4;
brewerslice = test.substring(brewersliceend,brewerslicestart) + " ";
fullname = brewerslice.concat(beerslice);
for (i=0;i<set.length;i++){
testset = set[i].getElementsByTagName("COMPARISON")
comparison = testset[0].firstChild.data
if (fullname == comparison){
var beer = set[i].getElementsByTagName("BEER")
var brewer = set[i].getElementsByTagName("BREWER")
var description = set[i].getElementsByTagName("DESCRIPTION")
var image = set[i].getElementsByTagName("IMAGE")
var abv = set[i].getElementsByTagName("ABV")
var location = set[i].getElementsByTagName("LOCATION")
var website = set[i].getElementsByTagName("WEBSITE")
var style = set[i].getElementsByTagName("STYLE")
document.getElementById("craftbeer").innerHTML= "<a href="+website[0].firstChild.data+" class='brewerlink' rel='external'>"+brewer[0].firstChild.data+"</a> <br />"
document.getElementById("beerinfo").innerHTML= description[0].firstChild.data
document.getElementById("beername").innerHTML= beer[0].firstChild.data
document.getElementById("beerimage").innerHTML= "<img src="+image[0].firstChild.data+" class='beerimage' alt="+beer[0].firstChild.data+" />"
document.getElementById("source").innerHTML= ""
document.getElementById("style").innerHTML= "Style: "+style[0].firstChild.data
document.getElementById("abv").innerHTML= "ABV: "+abv[0].firstChild.data
document.getElementById("location").innerHTML= "Point of Origin: "+location[0].firstChild.data
found = 1
}
}
}
}
}
// When the window loads, attach the event handlers to the links
// but only if AJAX is working
if (http) {
window.onload = function () {
var i, els = document.getElementsByTagName('a');
// Loop through all the links
for (i = els.length; i > 0; i--) {
// Attach the onclick handler to each link
els[i-1].onclick = sndReq;
}
}
}
</script>