Ajax Getting Started Tutorial: Ajax XMLHttpRequest

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.