Prototype使用學習手冊指南之ajax.js

來源:互聯網
上載者:User

和在我以前使用這個類庫的不少開發人員一樣,一開始,我不得不一頭紮進閱讀prototype.js的原始碼和實驗它的功能中。Prototype中的ajax.js提供了一個非常好用的ajax架構,一般應用中簡單的調用以下代碼就可以了

new Ajax.Request(
  url, {method: “get”,
  onSuccess: showFilter,
  onFailure: function(request){alert(”Server error!”)},
  onException: showError}
);

這個架構中提供了如下的對象和方法等:

Ajax對象:只有一個getTransport方法,返回一個XMLHttpRequest對象,另外有一個activeRequestCount屬性,反映當前正在處理的ajax數量

Ajax.Responders對象:繼承自Enumerable,管理全域Ajax的請求,具有如下方法:

register(responder):註冊一個管理ajax請求的對象

unregister(responder):撤銷一個管理ajax請求的對象

dispatch(callback, request, transport, json):觸發註冊的處理對象的方法

這個對象一般很少使用,系統中已經使用如下的代碼註冊了一個處理對象

Ajax.Responders.register({
 onCreate: function() {
  Ajax.activeRequestCount++;
 },
 onComplete: function() {
  Ajax.activeRequestCount–;
 }
});

Ajax.Base類:

Ajax的基類, 只有一個方法setOptions(options), 預設request參數如下,你可以在建立Ajax.request時指定:

method:'post’,
asynchronous: true,
contentType:'application/x-www-form-urlencoded’,
encoding:'UTF-8′,

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.