OK, I'm trying to get this about as right as I can while still keeping the code down. From what you (mwinter) write, it appears (and testing seemed to bear this out), I would need to create a separate request object and send it just in order to see if the mime type is as expected and that it would then be too late to change the mime type for that request. I would be glad to be wrong about this. However, since we don't really need to worry about overrideMimeType() being available because we are testing for its existence before we invoke it, I see no problem with just going ahead and using it. I did take to heart what you said about it making no sense to override to text/xml if text/html is what is wanted though. I had been getting some errors in FF that could only be eliminated by using self closing tags on the requested page. By changing the override to text/html, these errors went away.
Also, I had missed the first time through how you were saying that having an alert and returning false in the case where the request object couldn't be constructed didn't make too much sense in actual use. Since my code is in response to a "return get this.href" sort of onclick event, I have now chosen to return true if the request cannot be constructed. This will result in the link firing normally, loading the page if it is there and giving the server's error page for the event if the page is unavailable. If all goes well, I now return false, so that, since we now have the page as content on the 'top' page, the link will not fire.
Finally, I tried to adhere to the order in which you recommended things be carried out/invoked. Here's the new set up:
makeRequest:function(url) {
mybox.box.style.backgroundColor='';
mybox.close.className='close';
mybox.close.style.width='';
var http_request = null;
if (window.XMLHttpRequest&&(!window.ActiveXObject||/http/.test(window.location.href))) { // Mozilla, Safari, IE 7 live . . .
http_request = new XMLHttpRequest();
}
else if ((typeof createRequest == 'object') || (typeof createRequest == 'function'))
http_request = createRequest();
else if (window.ActiveXObject) { // IE (v7 locally)
/*@cc_on @*/
/*@if(@_jscript_version >= 5)
try {
http_request = new ActiveXObject('Msxml2.XMLHTTP');
} catch(e) {
try {
http_request = new ActiveXObject('Microsoft.XMLHTTP');
} catch(e) {
http_request = null;
}
}
@end @*/
}
if (!http_request)
return true;
http_request.open('GET', url, true);
if (http_request.overrideMimeType)
http_request.overrideMimeType('text/html');
http_request.onreadystatechange = function() {
if (http_request.readyState == 4 && (http_request.status == 200||!/http/.test(window.location.href)))
mybox.kid1.innerHTML = http_request.responseText;
else
mybox.kid1.innerHTML = "Loading...";
mybox.olay.style.height=Math.max(mybox.iecompattest().offsetHeight, mybox.iecompattest().scrollHeight)+'px';
mybox.olay.style.width=Math.max(mybox.iecompattest().offsetWidth, mybox.iecompattest().scrollWidth)-(mybox.ie6wa? mybox.ie6wa() : 0)+'px';
mybox.boxLoc(mybox.box);
};
http_request.send(null);
return false;
},
I'm still not clear on what the alternatives for testing only for a 200 response would be and what their implications for branching might afford, especially at that juncture in the code. However, it seems to me that if the page is missing at that point, having:
Loading . . .
just sit there until dismissed by the user (they can do that in my script), might not be so bad.