K
Kiwi_In_VT
Hi,
I'm a software guy, but brand new to JavaScript. I have my first
script cut, pasted and tweaked together and is WORKING GREAT on
Firefox. I thought before I used it on the real pages on my site I
should try it with IE.
I just get an 'error on page' message, and I don't know where to start
looking for the problem...
Any help would be appreciated
The pages on my site have a series of ads down one side. The goal of
the script is to download the html for the ads (currently 7 of them)
and then every minute reorder them randomly, concatenate them in the
new order, and stuff them in the table.
Here's the code (please excuse the old-school indentation scheme, it's
what I grew up with, I like it, and I'm too old to change):
window.onload = initAll;
var xhr = false;
var smallAds = [];
function initAll() {
getNewFile("ajaxSmallAds.php"); // gets it once, then keeps re-
ordering every minute
}
function getNewFile(fileName) {
makeRequest(fileName);
return false;
}
function randOrd(){
return (Math.round(Math.random())-0.5);
}
function showSmallAds() {
var s = "";
for (i=0; i<smallAds.length; i++) {
s += smallAds;
}
document.getElementById("buttonAdTable").innerHTML = s;
smallAds.sort(randOrd); // randomize for next call
setTimeout("showSmallAds()", 60 * 1000); // display the ads
randomly every 1 minute
}
function makeRequest(url) {
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else {
if (window.ActiveXObject) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) { }
}
}
if (xhr) {
xhr.onreadystatechange = showContents;
xhr.open("GET", url, true);
xhr.send(null);
}
else {
document.getElementById("raceX").innerHTML = "Sorry, but I
couldn't create a request";
}
}
function showContents() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
var outMsg = (xhr.responseXML &&
xhr.responseXML.contentType=="text/xml") ?
xhr.responseXML.getElementsByTagName("choices")[0].textContent :
xhr.responseText;
}
// else {
// var outMsg = "There was a problem with the request " +
xhr.status;
// }
var data = [];
data = outMsg.split("\n");
if (data[0] == "smallAds") {
for (i=1; i<data.length; i++) {
if (data != "") {
smallAds[i-1] = data;
}
}
// now call the function that will randomly place the ads from
now on...
showSmallAds();
}
}
}
I'm a software guy, but brand new to JavaScript. I have my first
script cut, pasted and tweaked together and is WORKING GREAT on
Firefox. I thought before I used it on the real pages on my site I
should try it with IE.
I just get an 'error on page' message, and I don't know where to start
looking for the problem...
Any help would be appreciated
The pages on my site have a series of ads down one side. The goal of
the script is to download the html for the ads (currently 7 of them)
and then every minute reorder them randomly, concatenate them in the
new order, and stuff them in the table.
Here's the code (please excuse the old-school indentation scheme, it's
what I grew up with, I like it, and I'm too old to change):
window.onload = initAll;
var xhr = false;
var smallAds = [];
function initAll() {
getNewFile("ajaxSmallAds.php"); // gets it once, then keeps re-
ordering every minute
}
function getNewFile(fileName) {
makeRequest(fileName);
return false;
}
function randOrd(){
return (Math.round(Math.random())-0.5);
}
function showSmallAds() {
var s = "";
for (i=0; i<smallAds.length; i++) {
s += smallAds;
}
document.getElementById("buttonAdTable").innerHTML = s;
smallAds.sort(randOrd); // randomize for next call
setTimeout("showSmallAds()", 60 * 1000); // display the ads
randomly every 1 minute
}
function makeRequest(url) {
if (window.XMLHttpRequest) {
xhr = new XMLHttpRequest();
}
else {
if (window.ActiveXObject) {
try {
xhr = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e) { }
}
}
if (xhr) {
xhr.onreadystatechange = showContents;
xhr.open("GET", url, true);
xhr.send(null);
}
else {
document.getElementById("raceX").innerHTML = "Sorry, but I
couldn't create a request";
}
}
function showContents() {
if (xhr.readyState == 4) {
if (xhr.status == 200) {
var outMsg = (xhr.responseXML &&
xhr.responseXML.contentType=="text/xml") ?
xhr.responseXML.getElementsByTagName("choices")[0].textContent :
xhr.responseText;
}
// else {
// var outMsg = "There was a problem with the request " +
xhr.status;
// }
var data = [];
data = outMsg.split("\n");
if (data[0] == "smallAds") {
for (i=1; i<data.length; i++) {
if (data != "") {
smallAds[i-1] = data;
}
}
// now call the function that will randomly place the ads from
now on...
showSmallAds();
}
}
}