var xmlHttpRequest;
function getXmlHttp(){
var xmlhttp=null;
if(window.XmlHttpRequest)
{
xmhttp=new XmlHttpRequest();
}
is(window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHttp");
}
return xmlhttp;
}
function populateList(){
var url="ln.jsp?username=williams&password=passw0rd";
if(!xmlHttpRequest)
{
xmlHttpRequest=getXmlHttp();
}
if(!xmlHttpRequest)
return;
xmlHttpRequest.open("GET",url,true);
xmlHttpRequest.onreadyStateChange=getResult;
xmlHttpRequest.send(null);
}
function getResult(){
if(xmlHttpRequest.readyState==4&&xmlHttpRequest.status==200)
{
document.getElementById("ln").innerHTML=xmlHttpRequest.responseText;
}
else
{
............................................................
}
}
本文介绍了一个使用JavaScript实现的AJAX请求示例,通过GET方式从服务器获取数据,并展示如何处理响应结果。示例中详细展示了如何创建XMLHttpRequest对象,设置请求参数及回调函数。
1117

被折叠的 条评论
为什么被折叠?



