I am using javascript to pull data from a URL and put it into a div:
function ahah(url, target) {
document.getElementById(target).innerHTML = 'Fetching fixtures...';
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
}
if (req != undefined) {
req.onreadystatechange = function() {ahahDone(url, target);};
req.open("GET", url, true);
req.send("");
}
}
function ahahDone(url, target) {
if (req.readyState == 4) { // only if req is "loaded"
if (req.status == 200) { // only if "OK"
document.getElementById(target).innerHTML = req.responseText;
} else {
document.getElementById(target).innerHTML=" Error:\n"+ req.status + "\n" +req.statusText;
}
}
}
function load(name, div) {
ahah(name,div);
return false;
}
load('http://www.domain.com/feeds/','content');
The problem is that if the URL to load is local it works fine (/feeds/), but when I change it to point to an external site (http://www.domain.com/feeds/) where I intend to hold the file I get an 'Error 0'.
I have checked the URL has the content available but unless it is local it will not work. Any feedback is very welcome, thank you.