欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
prototype 源碼解讀的第二部分 - Ajax.js
Ajax.js
/**
* 定義 Ajax 對象, 靜態(tài)方法 getTransport 方法返回一個(gè) XMLHttp 對象
*/
var Ajax = {
getTransport: function() {
return Try.these(
function() {return new ActiveXObject(‘Msxml2.XMLHTTP‘)},
function() {return new ActiveXObject(‘Microsoft.XMLHTTP‘)},
function() {return new XMLHttpRequest()}
) || false;
},
emptyFunction: function() {}
}
/**
* 我以為此時(shí)的Ajax對象起到命名空間的作用。
* Ajax.Base 聲明為一個(gè)基礎對象類(lèi)型
* 注意 Ajax.Base 并沒(méi)有使用 Class.create() 的方式來(lái)創(chuàng )建,我想是因為作者并不希望 Ajax.Base 被庫使用者實(shí)例化。
* 作者在其他對象類(lèi)型的聲明中,將會(huì )繼承于它。
* 就好像 java 中的私有抽象類(lèi)
*/
Ajax.Base = function() {};
Ajax.Base.prototype = {
/**
* extend (見(jiàn)prototype.js中的定義) 的用法真是讓人耳目一新
* options 首先設置默認屬性,然后再 extend 參數對象,那么參數對象中也有同名的屬性,那么就覆蓋默認屬性值。
* 想想如果我寫(xiě)這樣的實(shí)現,應該類(lèi)似如下:
setOptions: function(options) {
this.options.methed = options.methed? options.methed : ‘post‘;
..........
}
我想很多時(shí)候,java 限制了 js 的創(chuàng )意。
*/
setOptions: function(options) {
this.options = {
method:       ‘post‘,
asynchronous: true,
parameters:   ‘‘
}.extend(options || {});
}
}
/**
* Ajax.Request 封裝 XmlHttp
*/
Ajax.Request = Class.create();
/**
* 定義四種事件(狀態(tài)), 參考http://msdn.microsoft.com/workshop/author/dhtml/reference/properties/readystate_1.asp
*/
Ajax.Request.Events =
[‘Uninitialized‘, ‘Loading‘, ‘Loaded‘, ‘Interactive‘, ‘Complete‘];
/**
*
*/
Ajax.Request.prototype = (new Ajax.Base()).extend({
initialize: function(url, options) {
this.transport = Ajax.getTransport();
this.setOptions(options);
try {
if (this.options.method == ‘get‘)
url += ‘?‘ + this.options.parameters + ‘&_=‘;
/**
* 此處好像強制使用了異步方式,而不是依照 this.options.asynchronous 的值
*/
this.transport.open(this.options.method, url, true);
/**
* 這里提供了 XmlHttp 傳輸過(guò)程中每個(gè)步驟的回調函數
*/
if (this.options.asynchronous) {
this.transport.onreadystatechange = this.onStateChange.bind(this);
setTimeout((function() {this.respondToReadyState(1)}).bind(this), 10);
}
this.transport.setRequestHeader(‘X-Requested-With‘, ‘XMLHttpRequest‘);
this.transport.setRequestHeader(‘X-Prototype-Version‘, Prototype.Version);
if (this.options.method == ‘post‘) {
this.transport.setRequestHeader(‘Connection‘, ‘close‘);
this.transport.setRequestHeader(‘Content-type‘,
‘a(chǎn)pplication/x-www-form-urlencoded‘);
}
this.transport.send(this.options.method == ‘post‘ ?
this.options.parameters + ‘&_=‘ : null);
} catch (e) {
}
},
onStateChange: function() {
var readyState = this.transport.readyState;
/**
* 如果不是 Loading 狀態(tài),就調用回調函數
*/
if (readyState != 1)
this.respondToReadyState(this.transport.readyState);
},
/**
* 回調函數定義在 this.options 屬性中,比如:
var option = {
onLoaded : function(req) {...};
......
}
new Ajax.Request(url, option);
*/
respondToReadyState: function(readyState) {
var event = Ajax.Request.Events[readyState];
(this.options[‘on‘ + event] || Ajax.emptyFunction)(this.transport);
}
});
/**
* Ajax.Updater 用于綁定一個(gè)html元素與 XmlHttp調用的返回值。類(lèi)似與 buffalo 的 bind。
* 如果 options 中有 insertion(from dom.js) 對象的話(huà), insertion 能提供更多的插入控制。
*/
Ajax.Updater = Class.create();
Ajax.Updater.prototype = (new Ajax.Base()).extend({
initialize: function(container, url, options) {
this.container = $(container);
this.setOptions(options);
if (this.options.asynchronous) {
this.onComplete = this.options.onComplete;
this.options.onComplete = this.updateContent.bind(this);
}
this.request = new Ajax.Request(url, this.options);
if (!this.options.asynchronous)
this.updateContent();
},
updateContent: function() {
if (this.options.insertion) {
new this.options.insertion(this.container,
this.request.transport.responseText);
} else {
this.container.innerHTML = this.request.transport.responseText;
}
if (this.onComplete) {
setTimeout((function() {this.onComplete(this.request)}).bind(this), 10);
}
}
});
[Edit on 2005-07-06 17:46:10 By 澤欣(醒來(lái))]
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Ajax: Java BluePrints 和 Rails對它的封裝
Prototype.js--Javascript編寫(xiě)者的小軍刀 - 花錢(qián)的年華 - Blo...
ajax基礎
AJAX
AJAX – onreadystatechange 事件 | 菜鳥(niǎo)教程
ajax里xmlhttp.readyState==4 && xmlhttp.status==200的意思
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久