Need Help w/Quick AJAX Adjustment (do something if activex na)

I have this function for my AJAX:


function firstcheck() {
dtext = "";
		if (window.XMLHttpRequest)
  		{
  		xmlhttp=new XMLHttpRequest();
  		}
		else
  		{
  		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  		}
			xmlhttp.onreadystatechange=function()
  			{
  			if (xmlhttp.readyState==4 && xmlhttp.status==200)
    		{
    		dtext = xmlhttp.responseText;
    		}
  			}
xmlhttp.open("POST","/file.php",true);
xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
var tkey = "";
xmlhttp.send("tid="+ tkey +"");
}

Now, I want to add a bit of code that does something if ACTIVEX is not available or if the browser can’t support AJAX. How can I edit this to allow for that?

Cheers!
Ryan

You can just do:

if(ActiveXObject) {
alert(“yay we have activeX support”);
}
else {
alert(“nope, no activeX”);
}

Just add an if statement within you else statement to check whether xmlhttp is null or not. If so do something…

I’m trying to avoid jquery just to limit the size, but would I just do…


if(!xmlhttp) {
//no activex spotted
}

or should I just have an if statement before everything like:


if (!window.XMLHttpRequest && !ActiveXObject("Microsoft.XMLHTTP")) {
//no way for AJAX, so do this
} else {
//run rest of statement
}

Would that work?

Thanks
Ryan

For better well tested API I would recommend you to use jQuery AJAX which is pretty easier to implement.
http://docs.jquery.com/Ajax/jQuery.post#urldatacallbacktype