一个 Ajax.Updater例子

2 篇文章 0 订阅
2 篇文章 0 订阅
 转自: http://hi.baidu.com/ayasnoopy/
  1. function getContents()
  2. {
  3. var request_url ="test1.html";       // 需要获取内容的url
  4. var request_pars ='';//请求参数
  5. var myAjax =new Ajax.Updater('result', request_url,{// 将request_url返回内容绑定到id为result的容器中
  6. method      : 'get', //HTTP请求的方法,get or post
  7. parameters : request_pars,//请求参数
  8. onFailure   : reportError,//失败的时候调用 reportError 函数
  9. onLoading   : loading,//正在获得内容的时候
  10. onComplete : done     //内容获取完毕的时候
  11. });
  12. }
  13. function loading()
  14. {
  15. $('loading').style.display = 'block';
  16. }
  17. function done()
  18. {
  19. $('loading').style.display = 'none';
  20. }
  21. function reportError(request)
  22. {
  23. alert('Sorry. There was an error.');
  24. }

-----------------------------------------------------------------------------

上面的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>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值