创建xmlhttp对象!

第一步创建xmlhttp对象!
        try
        {

            var xmlHttp = false;
            
try
            {
                xmlHttp 
= new XMLHttpRequest();
            }
            
catch
            (trymicrosoft)
            {
                
try
                {
                    xmlHttp 
= new ActiveXObject("Msxml2.XMLHTTP");
                }
                
catch (othermicrosoft)
                {
                    
try
                    {
                        xmlHttp 
= new ActiveXObject("Microsoft.XMLHTTP");
                    }
                    
catch (failed)
                    {
                        xmlHttp 
= false;
                    }
                }
            }
            
if(!xmlHttp)
            {
                alert(
"无法创建 XMLHttpRequest 对象!");
            }


或者  简单..

function createXMLHttpRequest() {
if (window.ActiveXObject) {
xmlHttp 
= new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) {
xmlHttp 
= new XMLHttpRequest();
}
}

 

 

 

 

 

posted on 2009-06-23 09:47  5201314  阅读(307)  评论(0编辑  收藏  举报

导航