Navigetion

Sunday, July 29, 2012

Creating AJAX Crossbrowser XMLHttpRequest Object Instance

Although at the time of this writing, Microsoft’s Internet Explorer continues to dominate the browser market, competitors such as Firefox have been making significant headway. Therefore, it is as important as ever to make sure your Ajax applications are crossbrowser compatible. One of the most important aspects of the Ajax functionality is that it can be deployed across browsers rather seamlessly, with only a small amount of work required to make it function across most browsers (the exception being rather old versions of the current browsers). Consider the following code snippet, which instantiates an instance of the XMLHttpRequest object, and works within any browser that supports XMLHttpRequest.

  
//Create a boolean variable to check for a 
//valid Internet Explorer instance.
 var xmlhttp = false;
 if (window.XMLHttpRequest)
 {// code for IE7+, Firefox, Chrome, Opera, Safari
   xmlhttp=new XMLHttpRequest();
 }
 else
 {// code for IE6, IE5
   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
 }  
 

Click below button to check your browser.

No comments:

Post a Comment