六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 32|回复: 0

Ajax

[复制链接]

升级  42.67%

98

主题

98

主题

98

主题

举人

Rank: 3Rank: 3

积分
328
 楼主| 发表于 2013-1-29 11:22:40 | 显示全部楼层 |阅读模式
/** * @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>
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表