delta one handle kitchen faucets

Home Ajax browser support
« Home »
Jul 16th, 2012 Comments: 0

Ajax browser support

Plurk
Share this

Browser Support

Unfortunately, all browsers do not require the same JavaScript code in order to use AJAX.  It is necessary to use the XMLHttpRequest object and to make it compatible with some of the most commonly used web browsers (i.e. Firefox, Internet Explorer, Opera, and Firefox.

On way to determine the proper way to setup the XMLHttpRequest object for the web browser is to use a “try and catch” programming technique. This technique basically attempts to try a piece of code and catch any error that may occur.  Normally, if an error occurs in a piece of code, it will stop running.  Using “try and catch” if an error occurs, it is caught and the code continues to run.  The following example includes a piece of code that tries three different ways to create an XMLHttpRequest object.  The catch code will not be used unless there is an error.

Example: <html>

<body>

 

<script language=”javascript” type=”text/javascript”>

<!–

//Support Code for Browser

function ajaxFunction(){

var ajaxRequest;  // This is necessary for AJAX

 

try{

// For Firefox Opera, Safari

ajaxRequest = new XMLHttpRequest();

} catch (e){

// For Internet Explorer

try{

ajaxRequest = new ActiveXObject(“Msxml2.XMLHTTP”);

} catch (e) {

try{

ajaxRequest = new ActiveXObject(“Microsoft.XMLHTTP”);

} catch (e){

// Something is incorrect

alert(“Current browser does not work.”);

return false;

}

}

}

}

//–>

</script>

 

<form name=’someForm’>

Name: <input type=’text’ name=’user’ /> <br />

Date: <input type=’text’ name=’date’ />

</form>

</body>

</html>

 

In this JavaScript code example, three attempts are made to create the XMLHttpRequest object. In the first attempt is used for Firefox, Opera, and Safari browsers.  The remaining two attempts are for Internet Explorer.  If none of these attempts work, it is assumed that the browser being used is outdated and therefore not capable of supporting Ajax.

Leave a Reply

Your email address will not be published.

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>