-
function getContents()
-
{
-
var request_url ="test1.html"; // 需要获取内容的url
-
var request_pars ='';//请求参数
-
var myAjax =new Ajax.Updater('result', request_url,{// 将request_url返回内容绑定到id为result的容器中
-
method : 'get', //HTTP请求的方法,get or post
-
parameters : request_pars,//请求参数
-
onFailure : reportError,//失败的时候调用 reportError 函数
-
onLoading : loading,//正在获得内容的时候
-
onComplete : done //内容获取完毕的时候
-
});
-
}
-
function loading()
-
{
-
$('loading').style.display = 'block';
-
}
-
function done()
-
{
-
$('loading').style.display = 'none';
-
}
-
function reportError(request)
-
{
-
alert('Sorry. There was an error.');
-
}
-----------------------------------------------------------------------------
上面的js还有一种写法
<script language="javascript" src="include/prototype.js"></script>
<script language="javascript">
<!--
function getContents(request_url)
{
//var request_url = "http://localhost:8080/Createwebsite/web/showpic.asp?p_classParentID=39"; // 需要获取内容的url
var request_pars = '';//请求参数
var myAjax = new Ajax.Updater('result', request_url,{ // 将request_url返回内容绑定到id为result的容器中
method : 'get', //HTTP请求的方法,get or post
parameters : request_pars ,//请求参数
evalScripts: true //允许执行返回内容中的脚本代码
});
}
var myGlobalHandlers = {
onCreate: function(){
Element.show('state');
},
onLoading:function(){
Element.show('state');
},
onFailure:function(){
alert('Sorry. There was an error.');
},
onComplete: function() {
if(Ajax.activeRequestCount == 0){
Element.hide('state');
}
}
};
Ajax.Responders.register(myGlobalHandlers);
-->
</script>
<div id="state" style="display:none;"><img src="image/group101.gif">加载状态图片</div>
<div id="result">这里是容器 </div>
<a href="http://localhost:8080/Createwebsite/web/showpic.asp?p_classParentID=39" οnclick="getContents(this.href);return false;">看看update的用法 </a>