AJAX core code
This is the core code needed to create an AJAX object:
<script type="text/javascript">
function ajaxDataGet(){
var ajaxObject; //the variable that will store the object
try{
// Opera 8.0+, Firefox, Safari, Netscape 7
ajaxObject = new XMLHttpRequest();
}
catch (e){
// Internet Explorer
try{
ajaxObject = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
//if the above ActiveXObject did not work
try{
ajaxObject = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (e){
//if AJAX is not supported at all
alert("Your browser does not support AJAX!!");
return false;
}
}
}
}
</script>
The above is the core code to create an AJAX object.
The logical progression it follows is as such:
- Create a function to set up an AJAX object
- Create a variable within that function to store the AJAX object
- Use a try.....catch block to try to crate an AJAX object using XML HttpRequest()
- If that does not work, create an AJAX object using new ActiveXObject("Msxml2.XMLHTTP")
- If that does not work, create an AJAX object using new ActiveXObject("Microsoft.XMLHTTP")
- If that does not work, issue a message informing the user that their browser does not support AJAX
NOTE: You do not have to use the same exact code to create AJAX objects. But whatever code you use, the logical progression should be the same.




