Ajax browser support

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.

This entry was posted in Ajax Tutorials and tagged , , , , , , , , , , , , . Bookmark the permalink.

13 Responses to Ajax browser support

  1. You made some decent points there. I looked on the net for that problem and discovered most people will go coupled with using your web site.

  2. There are a couple of interesting points soon enough in this post but I don’t know if I see these people center to heart. You can find some validity but I’ll take hold opinion until I consider it further. Good post , thanks and we want much more! Combined with FeedBurner also

  3. Perhaps you need to revise the actual perl server in your hosting company, Live journal will be kinda gradual.

  4. so much excellent info on here, : D.

  5. Awesome! I appreciate your blog post to this matter. It has been useful. my blog: cityville cheats

  6. Good post and a nice summation of the problem. My only problem with the analysis is given that much of the population joined the chorus of deregulatory mythology, given vested interest is inclined toward perpetuation of the current system and given a lack of a popular cheerleader for your arguments, I’m not seeing much in the way of change.

  7. PHP says:

    I recognize there exists plenty of spam on this blog. Do you want support cleansing them up? I may help amongst courses!

  8. When I firstly commented I clicked the “Notify me when new comments are added” checkbox and after this every time a comments is newly added I recieve four e-mail with only one statement. Could there be by any means you may remove me from that service plan? Many thanks!

  9. script says:

    An impressive share, I just given this onto a colleague who was doing a little bit evaluation on this. And he in reality ordered me breakfast due to the fact I discovered it for him.. smile. Consequently allow me alter that: Thanks for the deal with! Having said that yeah thanks for spending the time to chat about this, I really feel strongly about it and adore reading additional on this topic. If possible, as you turn into expertise, would you mind updating your weblog with additional details? It?s quite useful for me. Giant thumb up for this internet page publish!

  10. Jobs Script says:

    I am impressed with this internet site , real I am a big fan . CHECK ME OUT BY CLICKING MY NAME!!!

  11. Outstanding post, I think people should learn a lot from this web site its rattling user genial .

  12. Rattling wonderful info can be found on weblog .

  13. This is certainly a good blog. I mean it. You may have a whole lot of knowledge about this matter, and also a whole lot appreciation. Moreover, you may understand how to get people to really behind it, naturally with the feedback. You have a layout here thats not much too fancy, still constitutes a huge statement as large as what you might be stating. Great job, absolutely.

Leave a Reply

Your email address will not be published.