代码之家  ›  专栏  ›  技术社区  ›  David

确定AJAX是否可行?

  •  0
  • David  · 技术社区  · 15 年前

    2 回复  |  直到 15 年前
        1
  •  8
  •   Orson    15 年前
    var xhr;
    if (window.XMLHttpRequest) {
        xhr = new XMLHttpRequest();
    }
    else if (window.ActiveXObject) {
        try {
            xhr = new ActiveXObject("Msxml2.XMLHTTP");
        } catch(err) { 
    
        }
    }
    else {
        //It couldn't find any of those Ajax objects
    }
    
    if(!xhr) {
        //Here you know now that Ajax is not possible with this client
    }
    

    更新:

    试试…杰森·怀亚特建议的接球。我错过了。

        2
  •  0
  •   Johan    15 年前

    而且,这让我想起了一个 bad example from The Daily WTF