Ajax Getting Started Tutorial: Ajax XMLHttpRequest
The XMLHttpRequest object makes Ajax possible.
In XMLHttpRequest's
The XMLHttpRequest object is the key Ajax.
This is from the existing Internet Explorer 5.5 released in July 2000, but was not fully discovered before people started talking about Ajax and Web 2.0 in 2005 years.
Create a XMLHttpRequest Object
Different browsers, use different methods to create a XMLHttpRequest object.
Internet Explorer uses a activexobject.
Other browsers use a built-in JavaScript object called XMLHttpRequest.
This is the simplest code that can be used to overcome this problem:
var xmlhttp=null
if (window. XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest ()
}
else if (window. ActiveXObject)
{
xmlhttp=new activexobject ("Microsoft.XMLHTTP")
}
Then test if the object window. XMLHttpRequest available. This object can be used in newer versions of Firefox, Mozilla,
The following example attempts to load Microsoft's latest version of "Msxml2.xmlhttp", available in Internet Explorer 6,
And then you go back to "Microsoft.XMLHTTP",
Available in Internet Explorer version 5.5 and later.
function Getxmlhttpobject ()
{
var xmlhttp=null;
try {//Firefox, Opera 8.0+, Safari xmlhttp=new XMLHttpRequest ();
catch (E) {//Internet Explorer try {xmlhttp=new ActiveXObject ("msxml2.xmlhttp");
catch (e) {xmlhttp=new ActiveXObject ("Microsoft.XMLHTTP");
} return xmlHttp;
The above example illustrates that
first create a variable XMLHTTP use your XMLHttpRequest object. Set the value to null.
Try to create objects in accordance with Web standards (Mozilla, Opera and Safari browsers): New XMLHTTP = XMLHttpRequest ()
Try to create an object Microsoft Way, available in Internet Explorer 6 and later: New XMLHTTP = ActiveXObject ("msxml2.xmlhttp")
If this catch error, try the way older people (Internet Explorer 5.5):
New XMLHTTP = ActiveXObject ("Microsoft.XMLHTTP")
Reprint please indicate from http://www.111cn.net/wy/yw.html