Hi there,
I have been developing a new application which employs the (new to me!) AJAX technologies/structure to avoid document refresh. Everything I have done thusfar works brilliantly in IE, but fails when I test using either NS7 or FF1. I have been to almost every link I have found at Rich Schwartz’s page (http://www.rhs.com/poweroftheschwartz/htdocs/LotusDominoAjax.htm), but simply cannot get the code to work. I am hoping that someone here may be able to point out some glaring error that I have made and set me straight.
Using all of the examples I have read, I created a javascript function to return the XMLHTTPObject…
function getXMLHTTP() {
var A = false;
try {
A = new ActiveXObject( “Msxml2.XMLHTTP” );
} catch(e) {
try {
A = new ActiveXObject(“Microsoft.XMLHTTP”);
} catch(oc) {
A = false;
}
}
if( !A && typeof XMLHttpRequest != “undefined” ) {
A = new XMLHttpRequest();
}
return A;
}
That works fine x-browser, and returns the object OK.
Here is the code excerpt which uses that function and attempts to send the request…
// Prepare the XMLHTTP object for an HTTP POST
xmlhttp = getXMLHTTP();
var sURL = “ABC (Australian Broadcasting Corporation)”;
xmlhttp.open( “GET”, sURL, false );
xmlhttp.onreadystatechange = manageStateChange;
// Execute the request
try {
xmlhttp.setRequestHeader( ‘If-Modified-Since’, ‘Fri, 31 Dec 1999 00:00:00 GMT’ ); // Eliminate cacheing issues
xmlhttp.send(null);
alert( “XML request sent” );
}
catch (e) {
alert( “Could not calculate at this time.”);
}
And here is the code which manages the state change…
function manageStateChange() {
alert( "Ready state changed to: " + xmlhttp.readyState );
switch( xmlhttp.readyState ) {
case 2, 3:
// Display a progress indicator
document.body.style.cursor=‘wait’;
break;
case 4:
document.body.style.cursor=‘default’;
thisDoc.Results1.value = xmlhttp.responseText;
break;
}
}
Some interesting observations…
If I use the command “xmlhttp.send()”, then the browser immediately returns the message “Could not calculate at this time”. If I use the command “xmlhttp.send(null)”, then the browser returns the message “XML request sent”, but does absolutely nothing.
Using IE when the script is initiated, I receive the messages “Ready state changed to: 1”, “Ready state changed to: 2”… until the ready state changes to 4, THEN I receive the message “XML request sent”. However, I never see these “ready state” messages with the other browsers (but I DO see the “XML request sent” message).
I would really appreciate some insight from those of you more “in the know” than I.
If I have neglected an important piece of code (in the interest of keeping this as short as possible), then please let me know and I’ll post more.
Cheers!
T.