JAVASCRIPT - HOW TO CREATE AJAX XML HTTP OBJECT AND TEST - Javascript Source Code

JAVASCRIPT - HOW TO CREATE XML/HTTP REQUEST OBJECT AND TEST TO ENSURE CREATION OF THAT OBJECT IS SUCCESSFUL

Home Short:

Create the Ajax XmlHttpRequest Object within a Function

There are several different ways to create an XmlHttpRequest object and depending upon the platform/environment the Javascript/Ajax code runs on, the creation of the XmlHttpRequest object may or may not be successful. For this reason, we need to use code to create the XmlHttpRequest object that takes into account the possibility that creation of the XmlHttpRequest object failed. This is done via try/catch statesments, where one method of creating the XmlHttpRequest object is tried. If it fails, the next catch statement will try a different method of creating the XmlHttpRequest object.

There are 3 possible ways of creating the XmlHttpRequest object, and if all 3 of the methods fail, the last catch statement will simply return false. If/when one of the attempts to create the XmlHttpRequest object succeeds, we return the function with the XmlHttpRequest object.

S
H
A
R
E