AJAX on older browsers

Internet Explorer 5 and 6 supported a similar technology to XMLHttpRequest.

Adding an IF statement to the JavaScript on the previous page allows you to cater for these outdated browsers plus any which do not support either method:

        
if (window.XMLHttpRequest) {
	var xmlrequest=new XMLHttpRequest();
} else if (window.ActiveXObject) {                        
	var xmlrequest=new ActiveXObject("Microsoft.XMLHTTP");
} else {
	alert("Your browser does not support Ajax so this page will not work fully.  Update!");
}
        

This code just replaces the original var xmlrequest=new XMLHttpRequest(); line in the code. If the standard approach exists then that is used. If not the Internet Explorer way is tried. If that is also not available just give the user a message.

submit to reddit Delicious Tweet