Ajax create object


AJAX create object

insert image description here

Create an XMLHttpRequest object

XMLHttpRequest is the basis of AJAX.

XMLHttpRequest object

All modern browsers support the XMLHttpRequest object (IE5 and IE6 use ActiveXObject).

XMLHttpRequest is used to exchange data with the server behind the scenes. This means that parts of a webpage can be updated without reloading the entire webpage.

Create an XMLHttpRequest object

All modern browsers (IE7+, Firefox, Chrome, Safari, and Opera) have built-in XMLHttpRequest objects.

Syntax for creating an XMLHttpRequest object:

variable=new XMLHttpRequest();

Older versions of Internet Explorer (IE5 and IE6) used ActiveX objects:

variable=new ActiveXObject("Microsoft.XMLHTTP");

To work with all modern browsers, including IE5 and IE6, please check whether the browser supports the XMLHttpRequest object. Creates an XMLHttpRequest object if supported. Create ActiveXObject if not supported:

example

var xmlhttp;
  if (window.XMLHttpRequest)
  {
    // IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
   xmlhttp=new XMLHttpRequest();
  }
  else
  {
    // IE6, IE5 浏览器执行代码
   xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }

Guess you like

Origin blog.csdn.net/m0_62617719/article/details/130372783