peterb1985
MIS
Hi,
I have a page which uses ajax to get info from a database and display it on screen with refreshing. This worked fine. I am now trying to put this text into a scrolling message which move across the screen but it doesn't work. If anyone could tell me where I'm going wrong I would be very greatful. Code below.
<html>
<head>
<title></title>
<script type="text/javascript">
msg = "";
spacer = "";
pos = msg.length;
function loopfunc() {
setTimeout("getGallery()",3000);
setTimeout("ScrollMessage()",200);
}
function ScrollMessage() {
newtext = msg.substring(pos, msg.length) + spacer + msg.substring(0, pos);
document.getElementById("scroll").innerHTML= newtext;
pos=pos+1;
if (pos > msg.length) {
pos = 0;
}
setTimeout("ScrollMessage()",200);
}
function getGallery() {
var url = "totalstoday2.cfm?" + Math.random();
var callback = processAjaxResponse;
executeXhr(callback, url);
}
var req;
function executeXhr(callback, url) {
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = callback;
req.open("GET", url, true);
req.send(null);
} // branch for IE/Windows ActiveX version
else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = callback;
req.open("GET", url, true);
req.send();
}
}
}
function processAjaxResponse() {
// only if req shows "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
var answer = req.responseText;
msg = req.responseText;
setTimeout("getGallery()",3000);
} else {
alert("There was a problem retrieving the XML data:\n" +
req.statusText);
setTimeout("getGallery()",3000);
}
}
}
</script>
</head>
<body onLoad="loopfunc()">
<table width="100%">
<tr>
<td id="scroll"></td>
</tr>
</table>
</body>
</html>
I have a page which uses ajax to get info from a database and display it on screen with refreshing. This worked fine. I am now trying to put this text into a scrolling message which move across the screen but it doesn't work. If anyone could tell me where I'm going wrong I would be very greatful. Code below.
<html>
<head>
<title></title>
<script type="text/javascript">
msg = "";
spacer = "";
pos = msg.length;
function loopfunc() {
setTimeout("getGallery()",3000);
setTimeout("ScrollMessage()",200);
}
function ScrollMessage() {
newtext = msg.substring(pos, msg.length) + spacer + msg.substring(0, pos);
document.getElementById("scroll").innerHTML= newtext;
pos=pos+1;
if (pos > msg.length) {
pos = 0;
}
setTimeout("ScrollMessage()",200);
}
function getGallery() {
var url = "totalstoday2.cfm?" + Math.random();
var callback = processAjaxResponse;
executeXhr(callback, url);
}
var req;
function executeXhr(callback, url) {
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = callback;
req.open("GET", url, true);
req.send(null);
} // branch for IE/Windows ActiveX version
else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = callback;
req.open("GET", url, true);
req.send();
}
}
}
function processAjaxResponse() {
// only if req shows "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200) {
var answer = req.responseText;
msg = req.responseText;
setTimeout("getGallery()",3000);
} else {
alert("There was a problem retrieving the XML data:\n" +
req.statusText);
setTimeout("getGallery()",3000);
}
}
}
</script>
</head>
<body onLoad="loopfunc()">
<table width="100%">
<tr>
<td id="scroll"></td>
</tr>
</table>
</body>
</html>