|
我在学习过程的遇到几个问题:
很多资料,对如何创建xmlHttpRequest对象及客户端处理都说明得很详细,如下,是我整理的一些代码:
<script type=“text/javascript”>
var xmlHttp;
function createXMLHttpRequest() //该方法建立一个XMLHttpRequest对象,对象初始化
{
if (window.ActiveXObject) //IE浏览器
{
xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
else if (window.XMLHttpRequest) //非IE浏览器
{
xmlHttp = new XMLHttpRequest();
}
}
function startRequest() //该方法发送请求
{
createXMLHttpRequest();
xmlHttp.onreadystatechange = handleStateChange;
//设置方法,来处理服务器返回的信息
xmlHttp.open(“GET”, “innerHTML.xml”, true); //建立对服务器的调用
//参数1:HTTP请求方法 参数2:请求的URL 参数3:是否等待调用的建立后,再执 行下面的方法,默认为True
xmlHttp.send(null); //发送请求
}
function handleStateChange()
{
……
//客户端接收服务器端返回的数据, xmlHttp.responseXML或xmlHttp. responseText
…… //处理服务器返回的信息,修改客户端页面,比如在页面上显示数据等
}
</script>
|