Categories: Prototype Api

AJAX PeriodicalUpdater() 方法 | Prototype教程

返回到:Prototype AJAX 教程

此 AJAX 方法定期执行 AJAX 请求并根据响应文本更新容器的内容。

容器是通过给定 HTML 元素的 ID 来指定的,比如分区或段落。请参见下面的示例。

回调在请求生命周期的不同点被调用,并且始终具有相同的参数列表。它们与其他选项一起传递给请求者。

语法

new Ajax.PeriodicalUpdater(container, url[, options]);

Ajax.PeriodicalUpdater 具有所有常用选项和回调,以及由Ajax.Updater() 添加的那些。.

此方法还有两个特定选项 –

选项描述
frequency默认值为 2
这是发出 AJAX 请求的最小间隔。
decay默认值为 1
这控制了响应不变时请求间隔增长的速率。

返回值

返回 AJAX PeriodicalUpdater 对象。

禁用和启用 PeriodicalUpdater

您可以通过简单地调用其停止方法来停止正在运行的 PeriodicalUpdater。如果你想稍后重新启用它,只需调用它的 start 方法。两者都没有争论。

例子

<html>
   <head>
      <title>Prototype examples</title>
      <script type = "text/javascript" src = "https://cdn.bootcdn.net/ajax/libs/prototype/1.7.3/prototype.min.js"></script>
      
      <script>
         function startTimer() {
            new Ajax.PeriodicalUpdater('datetime', '/cgi-bin/timer.cgi', {
               method: 'get', frequency: 3, decay: 2
            });
         }
      </script>
   </head>

   <body>
      <p>Click start button to see how Current Time changes.</p>
      <p>This example may not work in IE.</p>
      <br />
 
      <div id = "datetime">Current Time</div>
      <br />
      <br />
      <input type = "button" value = "Start" onclick = "startTimer();"/>
   </body>
</html>

这是timer.cgi脚本的内容:

#!/usr/bin/perl

print "Content-type: text/html\n\n";

$datetime = localtime;
print $datetime;
print "<br />";

返回到:Prototype AJAX 教程

terry

这个人很懒,什么都没有留下~

Share
Published by
terry

Recent Posts

聊聊vue3中的defineProps

在Vue 3中,defineP…

4 天 ago

在 Chrome 中删除、允许和管理 Cookie

您可以选择删除现有 Cooki…

1 周 ago

自定义指令:聊聊vue中的自定义指令应用法则

今天我们来聊聊vue中的自定义…

2 周 ago

聊聊Vue中@click.stop和@click.prevent

一起来学下聊聊Vue中@cli…

3 周 ago

Nginx 基本操作:启动、停止、重启命令。

我们来学习Nginx基础操作:…

4 周 ago

Vue3:手动清理keep-alive组件缓存的方法

Vue3中手动清理keep-a…

4 周 ago