javascript Instantiate AJAX

function AjaxRequest()
{
	var request = null;

	if(typeof window.XMLHttpRequest != "undefined")
	{
		request = new XMLHttpRequest();
	}
	else if(typeof window.ActiveXObject != "undefined")
	{
		try
		{
			request = new ActiveXObject("Microsoft.XMLHTTP");
		}
		catch(err) {
			request = null;
		}
	}

	return request;
}
This code first tests for a native object, which most modern browsers use, then for an ActiveX implementation to support IE6. Thanks to Sitepoint Tech Times email.

Updated: Tuesday 5th October 2010, 22:15pm

There are 0 comments

Leave a comment of your own

Comments are currently closed.