ITeye博客

我的AJAX类的使用(一个简单的异步组件)

eicesoft · 2007-09-05 15:34 · [网站分类]代码与软件发布 · Markdown

这个组件可以异步加载网页文件,需要我前面写的那个AJAX的组件支持!.

其组件代码AJAXDiv.js的源码 

function $(objid)
...{
    return document.getElementById(objid);
}

function $$(tagname)
...{
    return document.getElementsByTagName(tagname);
}

function AJAXDiv(objid,autoFix,loadclass)
...{
    //alert(objid);
    this._id=objid;
    this._loadClass=loadclass;
    this._autoFix=autoFix;
    this.init=function()
    ...{
        var obj=$(this._id);
        if((this._loadClass!=null)&&(this._loadClass!=""))
        ...{
            obj.className=this._loadClass;
        }
        var ajaxLib=new AJAXLib();
        ajaxLib.method="get";
        ajaxLib.URLString=obj.rl;
        ajaxLib.onCompletion=function()
        ...{
            //alert(ajaxLib.response);
            obj.innerHTML=ajaxLib.response;
        }
        ajaxLib.onLoading=function()
        ...{
            obj.innerHTML="<span class="fixie"></span><img src='loading.gif'>正在初始化...";
        }
        ajaxLib.onLoaded=function()
        ...{
            obj.innerHTML="<span class="fixie"></span><img src='loading.gif'>初始化完毕...";
        }
        ajaxLib.onInteractive=function()
        ...{
            obj.innerHTML="<span class="fixie"></span><img src='loading.gif'>正在解析响应...";
        }
        ajaxLib.Send();
        if(this._autoFix)
        ...{
            obj.style.overflow="visible";
        }
        else
        ...{
            obj.style.overflow="scroll";
        }
    };
    this.init();
}

测试文件test.htm:

 

<html>
<head>
    <link href="main.css" rel="stylesheet" rev="stylesheet">
    <script language="javascript" src="AJAXLib.js"></script>
    <script language="javascript" src="AJAXDiv.js"></script>
    <script language="javascript">...
        window.onload=function()
        ...{
            var ad=new AJAXDiv("ajaxdiv1",false);
            var ad2=new AJAXDiv("ajaxdiv2",true)
        }
    </script>
</head>
<body>
    <div class="ajaxdiv" id="ajaxdiv1" rl="a1.htm">
    </div>
    <div class="ajaxdiv" id="ajaxdiv2" rl="a2.htm">
    </div>
</body>
</html>

这样就可以异步加载网页文件了,而且有加载进度提示.

评论(0)

暂无评论。

评论功能维护中,当前仅展示历史评论。