您的位置:首页 > 其它

ajax 异步与同步

2010-10-18 10:03 232 查看
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="http://www.baidu.com/;
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="http://www.baidu.com/";
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;
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: