Forum Moderators: open
I can't seem to get true browser compatibility with this standard bit of AJAX code:-
<script language="javascript">
var XMLHttpRequestObject = false;if (window.XMLHttpRequest) {
XMLHttpRequestObject = new XMLHttpRequest();
} else if (window.ActiveXObject) {
XMLHttpRequestObject = new ActiveXObject("Microsoft.XMLHTTP");}
function getData(dataSource, divID)
{
if (XMLHttpRequestObject) {
var obj = document.getElementById(divID);
XMLHttpRequestObject.open("GET", dataSource);
XMLHttpRequestObject.onreadystatechange = function ()
{
if (XMLHttpRequestObject.readyState == 4 &&
XMLHttpRequestObject.status == 200) {
obj.innerHTML = XMLHttpRequestObject.responseText;
}
}
XMLHttpRequestObject.send(null);
}
}
The latest IE "fix" issued April 2006 seems to break it, and it doesn't seem to work in FireFox all the time, depending on how up to date your install of FF is.
Is there a "new" standard for setting up the XMLHttpRequestObject which is likely to give me more consistent results in light of the April IE patch and latest FF patches?
Thanks.
TJ
Take at look at the code here [developer.mozilla.org], there is a second name for the XMLHttpRequestObject in Internet Explorer.
Andrew
Here is the code I use for creating the request object, not sure if it will help you, but should only take you a second to try it. Let us know either way. :)
var ajax_connection = createRequest();
function createRequest()
{
var ajaxRequest;
try
{
ajaxRequest = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e1)
{
try
{
ajaxRequest = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e2)
{
ajaxRequest = new XMLHttpRequest();
}
}
return ajaxRequest;
}