Best method of Instantiating an XMLHttpRequest object

前端 未结 9 1458
一生所求
一生所求 2020-12-31 20:43

What is the best method for creating an XMLHttpRequest object?

It should work in all capable browsers.

9条回答
  •  無奈伤痛
    2020-12-31 21:00

    function CreateXmlHttpObj() {

    try {
        XmlHttpObj = new ActiveXObject("Msxml2.XMLHTTP");
    }
    catch (e) {
        try {
            XmlHttpObj = new ActiveXObject("Microsoft.XMLHTTP");
        }
        catch (oc) {
            XmlHttpObj = null;
        }
    }
    // if unable to create using IE specific code then try creating for Mozilla (FireFox) 
    if (!XmlHttpObj && typeof XMLHttpRequest != "undefined") {
        XmlHttpObj = new XMLHttpRequest();
    }
    

    }

提交回复
热议问题