Thought I would just report back my findings, now that I have it all working. The following client-side code (slightly abridged and anonymized) contains all the work-arounds I needed to address the prblems outlined in this thread and works on IE (8.0.6001), FF(3.5.9), and Chrome (5.0.375.55 beta). Still yet to test under older versions of browsers. Many thanks to all who responded.
I should also add that I needed to make sure that the server response needed to include:
Response.ContentType = "text/xml" ;
for it to work with IE. FF didn't mind if the ContentType was text/HTML but IE coughed.
Code to create an XMLHTTP request:
function GetXMLHTTPRequest ()
{
var activexmodes=["Msxml2.XMLHTTP", "Microsoft.XMLHTTP"] ; //activeX versions to check for in IE
if (window.ActiveXObject) //Test for support for ActiveXObject in IE first (as XMLHttpRequest in IE7 is broken)
{
for (var i=0; i < activexmodes.length ; i++)
{
try
{
return new ActiveXObject(activexmodes[i]) ;
}
catch (e)
{ //suppress error
}
}
}
else if (window.XMLHttpRequest) // if Mozilla, Safari etc
{
return new XMLHttpRequest () ;
}
else
{
return (false) ;
}
}
Code to return the text value of a record node:
function GetRecordElement (ARecordNode, AFieldName)
{
try
{
if (ARecordNode.getElementsByTagName (AFieldName) [0].textContent != undefined)
{
return (ARecordNode.getElementsByTagName (AFieldName) [0].textContent) ; // Chrome, FF
}
if (ARecordNode.getElementsByTagName (AFieldName) [0].text != undefined)
{
return (ARecordNode.getElementsByTagName (AFieldName) [0].text) ; // IE
}
return ("unknown") ;
}
catch (Exception)
{
ReportError ("(GetRecordElement): " + Exception.description) ;
}
}
Code to perform the AJAX request:
function GetRecord (s)
{
try
{
ReportStatus ("") ;
var xmlhttp = GetXMLHTTPRequest () ;
if (xmlhttp)
{
xmlhttp.open ("GET", "blahblah.com/AJAXget.asp?...etc", true) ;
if (xmlhttp.overrideMimeType)
{
xmlhttp.overrideMimeType("text/xml") ;
}
xmlhttp.setRequestHeader ("Content-Type", "text/xml; charset=\"utf-8\"") ;
xmlhttp.onreadystatechange = function ()
{
if (xmlhttp.readyState == 4)
{
if (xmlhttp.responseXML != null)
{
var xmlDoc = xmlhttp.responseXML;
var ResultNodes = xmlDoc.getElementsByTagName ("Result") ;
if (ResultNodes != null)
{
var PayloadNode = xmlDoc.getElementsByTagName ("Payload") ;
if (PayloadNode != null)
{
var ResultText = ResultNodes [0].firstChild.nodeValue ;
if (ResultText == "OK")
{
ReportStatus (ResultText) ;
var RecordNode = PayloadNode [0].firstChild ;
if (RecordNode != null)
{
UpdateRecordDisplay (RecordNode) ; // eventually calls GetRecordElement
}
else
{
ReportError ("RecordNode is null") ;
}
}
else
{
ReportError ("Unknown response:" + ResultText) ;
}
}
else
{
ReportError ("PayloadNode is null") ;
}
}
else
{
ReportError ("ResultNodes is null") ;
}
}
else
{
ReportError ("responseXML is null") ;
}
}
else
{
ReportStatus ("Status=" + xmlhttp.readyState) ;
}
}
ReportStatus ("Requesting data ...") ;
xmlhttp.send (null) ;
}
else
{
ReportError ("Unable to create request") ;
}
}
catch (err)
{
ReportError ("(GetRecord): " + err.description) ;
}
}