Best method of Instantiating an XMLHttpRequest object

前端 未结 9 1456
一生所求
一生所求 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:08

    This is what I use, it works fine for me:

        function request()
        {
            try
            {
                try
                {
                    return new ActiveXObject("Microsoft.XMLHTTP")
                }
                catch( e )
                {
                    return new ActiveXObject("Msxml2.XMLHTTP")
                }
            }
            catch(e) 
            {
                return new XMLHttpRequest()
            }
        }
    

提交回复
热议问题