Home >Web Front-end >JS Tutorial >How to quickly obtain Ajax communication objects

How to quickly obtain Ajax communication objects

php中世界最好的语言
php中世界最好的语言Original
2018-03-31 16:49:181519browse

This time I will show you how to quickly obtain Ajax communication objects, and what are the precautions for obtaining Ajax communication objects. The following is a practical case, let's take a look.

The examples are as follows:

function getXHR() {
  // 该方法用于获取Ajax通信对象
  var xhr = null;
  if (window.XMLHttpRequest != null &&
  window.XMLHttpRequest != undefined) {
  xhr = new XMLHttpRequest();
  } else {
  / 兼容早期的IE浏览器
  xhr = new ActiveXObject("Microsoft.XMLHTTP");
  }
  return xhr;
}

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to other related articles on the PHP Chinese website !

Recommended reading:

Use Ajax to upload Base64 format images during H5 development

##ajax implements paging query function

The above is the detailed content of How to quickly obtain Ajax communication objects. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn