Ajax


/**
* @author DylanChan
*/
var oHttp =
{
XMLHttpRequest:function()
{
try
{
//创建XMLHttpRequest对象
var request = new XMLHttpRequest();
return request;
}
catch(ex)
{
var arrXMLHttpRequest = ["MSXML2.XMLHTTP.5.0", "MSXML2.XMLHTTP.4.0", "MSXML2.XMLHTTP.3.0", "MSXML2.XMLHTTP", "Microsoft.XMLHTTP"];
for(var i = 0; i < arrXMLHttpRequest.length; i++)
{
try
{
var request = new ActiveXObject(arrXMLHttpRequest[i]);
return request;
}
catch(oError)
{}
}
}
throw new Error("MSXML Is Not Installed On Your System!");
},
Get:function(requestURL, fnLoadding, fnCallBack)
{
//获取XMLHttpRequest对象
var oRequest = oHttp.XMLHttpRequest();
if(oRequest)
{
//oRequest.open():创建新的Http请求,并指定此请求的提交方法,URL,以及验证信息
//get:用“Get”方式发送数据,只能256K
//requestURL:请求的URL,可以为绝对地址,或相对地址
//true:指定此请求方式为异步方式
oRequest.open("get", requestURL, true);
//调用加载loadding gif图片的方法
fnLoadding();
oRequest.onreadystatechange = function()
{
//0 - XMLHttpRequest对象还没有完成初始化,还没有调用send()方法
//1 - XMLHttpRequest对象开始发送请求(载入)已调用send()方法,正在发送请求
//2 - XMLHttpRequest对象的请求发送完成(载入完成)send()方法执行完成,已经接收到全部响应内容
//3 - XMLHttpRequest对象开始读取服务器的响应(交互)正在解析响应内容
//4 - XMLHttpRequest对象读取服务器响应结束(完成)响应内容解析完成,可以在客户端调用了
if(oRequest.readyState == 4)
{
if(oRequest.status == 200)
{
if(fnCallBack)
{
fnCallBack(oRequest.responseText);
}
}
}
}
oRequest.send(null);
}
}
}



<script type="text/javascript">
function displayLoadImage(oElement)
{
while (oElement.hasChildNodes())
{
//利用循环删除oElement下重复的节点,保留一个
oElement.removeChild(oElement.lastChild);
}
var oImg = document.createElement("img");
oImg.setAttribute("src", "/TheOneHRWeb/images/loadding_indicator.gif");
oElement.appendChild(oImg);
}

function fnLoadding()
{
displayLoadImage(document.getElementById("appendImg"));
}
</script>



<body>
<span id="appendImg"></span>
</body>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值