AJAX 创建 XMLHttpRequest对象
2006-10-10 18:32
585 查看
<script language="javascript">
var XMLHttpReq = false;
//XMLHttpRequest
function createXMLHttpRequest()
{
if(window.XMLHttpRequest)
{
//Mozilla
XMLHttpReq = new XMLHttpRequet();
}
else if(window.ActionXObject)
{
//IE
try{
XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try{
XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){}
}
}
}
//
function sendRequest(url)
{
createXMLHttpRequest();
XMLHttpReq.open("GET", url, true);
XMLHttpReq.onreadystatechange = processResponse; //??
XMLHttpReq.send(null); //
}
//处理返回信息函数
function processResponse()
{
if(XMLHttpReq.readyState ==4)
{//判断对象状态
if(XMLHttpReq.status ==200)
{//信息已经成功返回,开始处理信息
var res = XMLHttpReq.responseXML.getElementsByTagName("res")[0].firstChild.data;
window.alert(res);
}
else
{//页面不正常
window.alert("您所请求的页面有异常.");
}
}
}
var XMLHttpReq = false;
//XMLHttpRequest
function createXMLHttpRequest()
{
if(window.XMLHttpRequest)
{
//Mozilla
XMLHttpReq = new XMLHttpRequet();
}
else if(window.ActionXObject)
{
//IE
try{
XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");
}
catch(e)
{
try{
XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");
}
catch(e){}
}
}
}
//
function sendRequest(url)
{
createXMLHttpRequest();
XMLHttpReq.open("GET", url, true);
XMLHttpReq.onreadystatechange = processResponse; //??
XMLHttpReq.send(null); //
}
//处理返回信息函数
function processResponse()
{
if(XMLHttpReq.readyState ==4)
{//判断对象状态
if(XMLHttpReq.status ==200)
{//信息已经成功返回,开始处理信息
var res = XMLHttpReq.responseXML.getElementsByTagName("res")[0].firstChild.data;
window.alert(res);
}
else
{//页面不正常
window.alert("您所请求的页面有异常.");
}
}
}
相关文章推荐
- AJAX - 创建 XMLHttpRequest 对象
- 创建ajax中的xmlhttprequest对象
- Ajax处理XML,XMLHttpRequest对象的创建和访问servlet并返回xml数据到页面展示
- AJAX - 创建 XMLHttpRequest 对象
- AJAX - 创建 XMLHttpRequest 对象
- AJAX学习笔记:创建XMLHttpRequest对象的五步骤
- 解析ajax核心XMLHTTPRequest对象的创建与浏览器的兼容问题
- ajax-创建XMLHttpRequest对象
- AJAX中创建XMLHttpRequest对象实例
- AJAX - 创建 XMLHttpRequest 对象
- 使用ajax访问服务器时---创建XMLHttpRequest对象
- AJAX - 创建 XMLHttpRequest 对象
- Ajax中封装创建XMLHttpRequest对象的方法
- Ajax基础--创建XMLHttpRequest对象
- AJAX创建XMLHttpRequest对象实例
- Ajax中XMLHttpRequest对象的创建和servlet中数据的交互
- AJAX - 创建 XMLHttpRequest 对象
- 创建xmlHttpRequest对象在FireFox中支持Ajax
- AJAX-创建XMLHttpRequest对象