- 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
廣告