Forum Moderators: open
I have a ColdFusion site with a page running an AJAX XMLHttpRequest on an include page division that polls for new database data every 5 seconds. This also keeps the 20 minute session alive, unless the session is lost via a server reboot etc, in which case a security exception occurs and loads the login page. The problem is, the login page loads in the include page division. My question is. How do I break the login page out of the include page division?
This is my simplified main page:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Home</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="PRAGMA" content="NO-CACHE" />
<meta http-equiv="CACHE-CONTROL" content="NO-CACHE" />
<meta http-equiv="Expires" content="-1" />
<script src="javascript/ajax.js" type="text/javascript"></script>
</head>
<body onload="ajax(page,'scriptoutput')">
<span id="scriptoutput"></span>
</body>
</html>
This is my JavaScript page:
// JavaScript Document
var page = "index.cfm?go=c.data";
function ajax(url,target) {
// native XMLHttpRequest object
//document.getElementById(target).innerHTML = 'Loading...';
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = function() {ajaxDone(target);};
req.open("GET", url, true);
req.send(null);
// IE/Windows ActiveX version
} else if (window.ActiveXObject) {
req = new ActiveXObject("Microsoft.XMLDOM");
if (req) {
req.onreadystatechange = function() {ajaxDone(target);};
req.open("GET", url, true);
req.send(null);
}
}
setTimeout("ajax(page,'scriptoutput')", 5000);
}
function ajaxDone(target) {
// only if req is "loaded"
if (req.readyState == 4) {
// only if "OK"
if (req.status == 200 ¦¦ req.status == 304) {
results = req.responseText;
document.getElementById(target).innerHTML = results;
} else {
document.getElementById(target).innerHTML="ajax error:\n" +
req.statusText;
}
}
}
This is my simplified include page:
<p>Data</p>
You obviously know what you're doing -- for example, you know that setTimeout(), argument[0] really aught to be a string -- but you've made a trivial oversight. From ajaxDone, req must obviously be global, however, you failed to declare it global with var req (similar to var page) and are depending upon ajax() to make it global. Like I said, it's trivial.
I'm unsure what an "include page division" is. Do you mean a login realm?