AJAX - The Complete Reference

(avery) #1

Chapter 3: XMLHttpRequest Object 65


PART I


should be avoided as it is focused on the scripting needs of MS Office Applications and will
trigger an ActiveX security dialog when used in Internet Explorer.

At the time of this edition’s writing, MSXML 6, which is provided with Vista, is the most
up to date and standards-compliant XML parser released by Microsoft. However, if you are
running Vista or have installed IE7 you won’t need to know this for basic Ajax duties as the
browser can use the native XHR. Given the room for confusion as to what ActiveX XHR
possibilities are available, a simple testing program is provided for you to see what is
supported by your browser. The script is quite straightforward and simply tries a variety of
ways to instantiate the XHR object, as well as enumerate its properties and methods. A few
captures of this script in action are shown in Figure 3-1.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Chapter 3 : XMLHttpRequest Object Tester</title>
<script type="text/javascript">

function XHRTester()
{
var nativeXHR = false;
var activeX = "";
var commObject = null;
try
{
commObject = new XMLHttpRequest();
nativeXHR = true;
}
catch(e) {}

/*
* Testing purposes only. See createXHR wrapper for adopted pattern
* If you use "MSXML2.XMLHTTP.5.0" you will be prompted by IE so it is
* omitted here
*/
var activeXStrings = ["Msxml2.XMLHTTP.6.0", "Msxml2.XMLHTTP.4.0",
"Msxml2.XMLHTTP.3.0", "Msxml2.XMLHTTP",
"Microsoft.XMLHTTP"];

for (var i=0; i < activeXStrings.length; i++)
{
try {
commObject = new ActiveXObject(activeXStrings[i]);
activeX += activeXStrings[i] + ", ";
}
catch (e) { }
}
Free download pdf