This script sends a request to a Apache web server every 500ms to retrieve an XML document using AJAX. This script functioned correctly on all the browsers listed below until recently. Now the XMLHttpObject readyState will equal 4 for a minute or so but then will end up toggling between 0 and 1. When I refresh the web page, readyState goes back to 4 but again ends up toggling between 0 and 1 after a minute or so.
I am pretty certain this error started to occur after we were forced to enable IPV6. I ve tested the script on several computers using Internet Explorer 7, Internet Explorer 8, Firefox 3.0.15, and Firefox 3.5.5. Currently it only functions correctly under Internet Explorer 7 and 8.
Does anyone have any suggestions on how to get this to function correctly under Firefox?
HTML & Javascript Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="css/master_default.css">
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<title>Monitor</title>
</head>
<div id= screen_container >
<div id= data_tables >
<div id= data_tables_heading class= page_container_heading >Real-Time Data Tables</div>
<div id="table_holder"></div>
</div>
</div>
<script type= text/javascript src= scripts/jquery.js ></script>
<!-- Handles AJAX server interface to retrieve XML positioning data. -->
<script language="javascript" type="text/javascript">
var ifspe_server_address = http://10.0.0.1:8080/ ;
var ifspe_positioning_dto_filename = digital_receiver_ifspe_dto.xml ;
var xml_http_object_positioning_dto = getXMLHttpObject();
get_ifspe_positioning_dto();
var ifspe_status_message_dto_filename = ifspe_status_message_dto.xml ;
var xml_http_object_status_message_dto = getXMLHttpObject();
get_ifspe_status_message_dto();
var refresh_data_id = window.setInterval("get_ifspe_positioning_dto()", 500);
var refresh_status_messages = window.setInterval("get_ifspe_status_message_dto()", 500);
var updating_state = 1;
// Write status message to text box.
function update_status_message(status_message_text)
{
if(updating_state == 1)
{
var msg = document.getElementById("status_message_value");
msg.innerHTML = status_message_text;
}
}
// Write status message to text box.
function update_debug_message(debug_message_text)
{
if(updating_state == 1)
{
var msg = document.getElementById("debug_message_value");
msg.innerHTML = debug_message_text;
}
}
// Retrieve XML HTTP object based on browser type.
function getXMLHttpObject()
{
var httpObj;
// Use this for Internet Explorer browsers.
if(window.ActiveXObject)
{
httpObj = new ActiveXObject("Microsoft.XMLHTTP");
}
// Use this for Firefox browsers.
else if(window.XMLHttpRequest)
{
httpObj = new XMLHttpRequest();
}
return httpObj;
}
// Sends request for XML Status Message Data Transfer Object (DTO) file to server.
function get_ifspe_status_message_dto()
{
var msg;
msg = "AJAX readyState: " + xml_http_object_status_message_dto.readyState;
update_debug_message(msg);
// Not sure if this abortion is helpful.
if(xml_http_object_status_message_dto.readyState > 0 &&
xml_http_object_status_message_dto.readyState < 4)
{
xml_http_object_status_message_dto.abort();
}
else
{
// Added ?vers="+new Date().getTime() to the server address so that it always gets a new XML file and not a cached version.
xml_http_object_status_message_dto.open("GET",
ifspe_server_address+ifspe_status_message_dto_filename+"?vers="+new Date().getTime(), true);
xml_http_object_status_message_dto.onreadystatechange = ifspe_status_message_dto_handler;
xml_http_object_status_message_dto.send(" ");
}
}
// Handles new XML file available event.
function ifspe_status_message_dto_handler()
{
// If start/stop button is set to start (run).
if(updating_state == 1)
{
if(xml_http_object_status_message_dto.readyState == 4)
{
if(xml_http_object_status_message_dto.status == 200)
{
// Get XML data.
var response = xml_http_object_status_message_dto.responseXML;
var status_message_root = response.getElementsByTagName("STATUS_MESSAGE_FILE");
// Parse xml file for status message tag.
if(status_message_root != null)
{
if(status_message_root[0] != null)
{
var message = status_message_root[0].getElementsByTagName("MESSAGE");
// Parse xml file for message tag.
if(message[0] != null)
{
// Get message tag.
var message_text = message[0].childNodes[0].nodeValue;
// Update status message.
update_status_message(message_text);
}
}
}
}
}
}
}
// Sends request for XML Positioning Data Transfer Object (DTO) file to server.
function get_ifspe_positioning_dto()
{
// Not sure if this abortion is helpful.
if(xml_http_object_positioning_dto.readyState > 0 && xml_http_object_positioning_dto.readyState < 4)
{
xml_http_object_positioning_dto.abort();
}
else
{
// Added ?vers="+new Date().getTime() to the server address so that it always gets a new XML file and not a cached version.
xml_http_object_positioning_dto.open("GET",
ifspe_server_address+ifspe_positioning_dto_filename+"?vers="+new Date().getTime(), true);
xml_http_object_positioning_dto.onreadystatechange = ifspe_positioning_dto_handler;
xml_http_object_positioning_dto.send(" ");
}
}
// Parse XML data.
//function handle_response()
function ifspe_positioning_dto_handler()
{
// If start/stop button is set to start (run).
if(updating_state == 1)
{
if(xml_http_object_positioning_dto.readyState == 4)
{
if(xml_http_object_positioning_dto.status == 200)
{
// Get XML data.
var response = xml_http_object_positioning_dto.responseXML;
//
// Log new XML data (Only works for Internet Explorer browsers).
//
if(logging_state == 1)
{
if(window.ActiveXObject)
{
var digital_receiver = response.getElementsByTagName("DIGITAL_RECEIVER");
// Process data.
}
}
}
else if(xml_http_object_positioning_dto.status == 404)
{
alert("URL does not exist!");
}
else
{
//alert("Status is "+httpObj.status);
}
}
}
}
</script>
</html>