- Prototype 教程
- Prototype - 主页
- Prototype - 简短概述
- Prototype - 有用的功能
- Prototype - 实用方法
- Prototype - Element 对象
- Prototype - 数值处理
- Prototype - 字符串处理
- Prototype - 数组处理
- Prototype - 哈希处理
- Prototype - 基本对象
- Prototype - 模板化
- Prototype - 枚举
- Prototype - 事件处理
- Prototype - 表单管理
- Prototype - JSON 支持
- Prototype - AJAX 支持
- Prototype - 表示范围
- Prototype - 周期性执行
- Prototype 有用资源
- Prototype - 快速指南
- Prototype - 有用资源
- Prototype - 讨论
Prototype - AJAX Responders() 方法
AJAX Ajax.Responders 让你可以注册全局监听器以监听基于 Prototype 的 AJAX 请求的每个步骤。
有两个 Responders,一个用于注册监听器,另一个用于取消注册监听器。
语法
Ajax.Responders.register(responder); Ajax.Responders.unregister(responder);
返回值
无。
取消注册一个 Responder
如果你计划取消注册一个 responder,请务必先定义它,然后再将引用传递给 register,最后,在时机成熟时,将其传递给 unregister。
示例
以下是一个通过监视 onCreate 和 onComplete 事件来计算当前正在进行中的 AJAX 请求数量的示例。
多次单击提交按钮,然后查看结果 −
<html>
<head>
<title>Prototype examples</title>
<script type = "text/javascript" src = "/javascript/prototype.js"></script>
<script>
function SubmitRequest() {
new Ajax.Request('/cgi-bin/ajax.cgi', {
method: 'get',
onSuccess: successFunc
});
}
Ajax.Responders.register({
onCreate: function() {
var count = Ajax.activeRequestCount++;
var container = $('requests');
container.update(count);
},
onComplete: function() {
var count = Ajax.activeRequestCount--;
var container = $('requests');
container.update(count);
}
});
function successFunc(response) {
var container = $('notice');
var content = response.responseText;
container.update(content);
}
</script>
</head>
<body>
<p>Click Submit button many times and see the result.</p>
<br />
<div id = "notice">Current Notice</div>
<br />
<div id = "requests">Current Request</div>
<br />
<input type = "button" value = "Submit" onclick = "SubmitRequest();"/>
</body>
</html>
以下是 ajax.cgi 的内容
#!/usr/bin/perl print "Content-type: text/html\n\n"; print "This content is returned by AJAX cgi
"; print "Current Time " . localtime;
输出
prototype_ajax_tutorial.htm
广告