Forum Moderators: open
The code follows
// JScript source code
<script>
function getXMLObj()
{
if (window.XMLHttpRequest)
{ // Mozilla, Safari,...
http_request = new XMLHttpRequest();
if (http_request.overrideMimeType)
{
http_request.overrideMimeType('text/xml');
return(http_request);// See note below about this line
}
}
else if (window.ActiveXObject)
{ // IE
try
{
http_request = new ActiveXObject("Msxml2.XMLHTTP");
return(http_request);
}
catch (e)
{
try
{
http_request = new ActiveXObject("Microsoft.XMLHTTP");
return(http_request);
}
catch (e)
{alert("Your Browser settings not suitable");
}
}
}
}
var XMLObj;
function getCons()
{
XMLObj=new getXMLObj();
url="test.aspx";
XMLObj.onreadystatechange=loadItems;
XMLObj.open('GET',url,true);
XMLObj.send(null);
}
function loadItems()
{
if (XMLObj.readyState==4)
{
var obj=document.getElementById("myDIV");
obj.innerHTML=XMLObj.responseText;
}
}
</script>
var msxmlhttp = new Array(
'Msxml2.XMLHTTP.5.0',
'Msxml2.XMLHTTP.4.0',
'Msxml2.XMLHTTP.3.0',
'Msxml2.XMLHTTP',
'Microsoft.XMLHTTP');
for (i=0;i<msxmlhttp.length;i++) {
try {
thisConn = new ActiveXObject(msxmlhttp[i]);
} catch (e) {
thisConn = null;
}
}
if(!thisConn && typeof XMLHttpRequest!= "undefined") {
thisConn = new XMLHttpRequest();
}
if (!thisConn) {
thisConn = false;
} Hope it's helpful.
The above code finds window.XMLHttpRequest for IE,
and so it does not run the else to get an ActiveX object.
But there is no return value for a browser that does support
XMLHttpRequest but does not support overrideMimeType,
as in IE7.