Ajax同步与异步传输的示例代码

(编辑:jimmy 日期: 2024/10/10 浏览:2)

复制代码 代码如下:
//同步传输模式  

function RequestByGet(nProducttemp,nCountrytemp)  
{  
    var xmlhttp  

    if (window.XMLHttpRequest)    
    {    
         //isIE   =   false;    
         xmlhttp   =   new   XMLHttpRequest();    
    }    
    else if (window.ActiveXObject)  
    {    
         //isIE   =   true;    
         xmlhttp   =   new   ActiveXObject("Microsoft.XMLHTTP");    
    }  

    //Web page location.  
    var URL="https://www.jb51.net/;  
    xmlhttp.open("GET",URL, false);  
    //xmlhttp.SetRequestHeader("Content-Type","text/html; charset=Shift_JIS")  
    xmlhttp.send(null);  
    var result = xmlhttp.status;  

    //OK  
    if(result==200)  
    {  
        document.getElementById("div_RightBarBody").innerHTML=xmlhttp.responseText;  
    }  
    xmlhttp = null;  
}  

 
//异步传输模式  
var xmlhttp  

function RequestByGet(nProducttemp,nCountrytemp)  
{  
    if (window.XMLHttpRequest)    
    {    
         //isIE   =   false;    
         xmlhttp   =   new   XMLHttpRequest();    
    }    
    else if (window.ActiveXObject)  
    {    
         //isIE   =   true;    
         xmlhttp   =   new   ActiveXObject("Microsoft.XMLHTTP");    
    }  

    //Web page location.  
    var URL="https://www.jb51.net/";  
    xmlhttp.open("GET",URL, true);  
    xmlhttp.onreadystatechange = handleResponse;  
    //xmlhttp.SetRequestHeader("Content-Type","text/html; charset=UTF-8")  
    xmlhttp.send(null);    
}  

function handleResponse()  
{  
    if(xmlhttp.readyState == 4 && xmlhttp.status==200)  
    {  
        document.getElementById("div_RightBarBody").innerHTML=xmlhttp.responseText;  
        xmlhttp = null;  
    } 
}

一句话新闻

高通与谷歌联手!首款骁龙PC优化Chrome浏览器发布
高通和谷歌日前宣布,推出首次面向搭载骁龙的Windows PC的优化版Chrome浏览器。
在对骁龙X Elite参考设计的初步测试中,全新的Chrome浏览器在Speedometer 2.1基准测试中实现了显著的性能提升。
预计在2024年年中之前,搭载骁龙X Elite计算平台的PC将面世。该浏览器的提前问世,有助于骁龙PC问世就获得满血表现。
谷歌高级副总裁Hiroshi Lockheimer表示,此次与高通的合作将有助于确保Chrome用户在当前ARM兼容的PC上获得最佳的浏览体验。