Ajax Working With browser

Ajax unfortunately doesn’t have same code for all browser, it has little bit different for all the browser. The keystone of Ajax is XMLHttpRequest object. And it will be very necessary for you to know about the XMLHttpObject, how it makes all browser compactible with the code.
<script type="text/javascript">
function ajaxFunction()
var xmlhttp;
if (window.XMLHttpRequest)
  // code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
else if (window.ActiveXObject)
  // code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  alert("Your browser does not support XMLHTTP!");

In the above javascript code, we try three times to make this XMLhttpRequest Object. Creation of the object is done with the try catch block, the try catch block works as basically it attempts to try a piece of code and if that piece causes the “error” it catches the error.
1.If you can see the code above you can notice that we first create a variable called xmlhttp to hold the XMLHttpRequest object.
2.Then next step is to creating the object XMLHttpRequest object. As xmlhttp= new XMLHttpRequest()
3.If the above code fails, try xmlhttp = new ActiveXObject (“Microsoft XMLHTTP). It is used for IE6 and IE5.
4.If that one is also doesn’t work, the it means that the user uses very outdated browser, so that the browser doesn’t support XMLHTTP.
Note: The code above can be used every time you need to create an XMLHttpRequest object, so just copy and paste it every time you want to use Ajax.
Scroll to Top