Heim  >  Artikel  >  Backend-Entwicklung  >  创建XMLHttpRequest对象的方法_PHP教程

创建XMLHttpRequest对象的方法_PHP教程

WBOY
WBOYOriginal
2016-07-13 17:36:28699Durchsuche

方法一:推荐

// 创建一个布尔型变量

var xmlhttp = false;

// 检查使用的是否为IE浏览器

try{

    // 如果JS的版本大于5

    xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");

    alert("You are using Microsoft Internet Explorer.");

}catch(e){

    // 如果不是,则使用老版本的ActiveX对象

    try{

        // 如果使用的是IE浏览器

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

        alert("You are using Microsoft Internet Explorer.");

    }catch(e){

        // 使用非IE浏览器

         xmlhttp = false;

    }

}

// 如果使用的是IE非浏览器

if(!xmlhttp && typeof XMLHttpRequest != undefined){

    xmlhttp = new XMLHttpRequest();

    alert("You are not using Microsoft Internet Explorer.");

}

方法二:

var xmlhttp;
// 如果ActiveX对象可用,则使用的肯定是IE浏览器
(!window.ActiveXObject){
    xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}else{
    // 使用Javascript方法处理  
    xmlhttp = new XMLHttpRequest();
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/508226.htmlTechArticle方法一:推荐 // 创建一个布尔型变量 var xmlhttp = false; // 检查使用的是否为IE浏览器 try{ // 如果JS的版本大于5 xmlhttp = new ActiveXObject("Msxml2.X...
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn