2
是否有任何類(如goog.ui.dialog
)讓我顯示一個對話框,其內容可以從ajax從另一個文件中獲取?使用谷歌關閉庫的AJAX窗口(彈出)
- goog.ui.Dialog是這個目標的合適類嗎?
- 我是否應該通過其他基本類實現它,如
good.net.XHR
和goog.ui.Popup
?
是否有任何類(如goog.ui.dialog
)讓我顯示一個對話框,其內容可以從ajax從另一個文件中獲取?使用谷歌關閉庫的AJAX窗口(彈出)
good.net.XHR
和goog.ui.Popup
?您可以擴展goog.ui.dialog並獲取內容。
一個簡單的例子至極可以幫助你:
my.ui.Dialog = function(opt_iframe) {
goog.ui.Dialog.call(this, null, opt_iframe);
this.xhr_ = new goog.net.XhrIo();
this.xhr_.addEventListener(goog.net.EventType.COMPLETE,
this.onComplete_, false, this);
goog.events.listen(this, goog.ui.Dialog.EventType.SELECT,
this.dispatch_, false, this);
};
my.ui.Dialog.prototype.buildWindow_ = function (responseJson) {
this.setTitle(responseJson.title);
this.setContent(responseJson.content);
this.setButtonSet(eval(responseJson.buttons));
};
my.ui.Dialog.EventType = {
'COMPLETE': 'complete'
};
my.ui.Dialog.prototype.onComplete_ = function (event) {
var json = this.xhr_.getResponseJson()
this.buildWindow_ (json);
this.reposition();
};
my.ui.Dialog.prototype.send = function (uri, method, post_data) {
this.xhr_.send(uri, method, post_data, null, {'X-DIALOG':'AJAX'});
};
goog.inherits (my.ui.Dialog, goog.ui.Dialog);
這是使用JSON的響應打造ui.Dialog這樣的:
{"buttons": "goog.ui.Dialog.Buttons.OK_CANCEL",
"content": "<html><body><h1>Hello</h1></body></html>",
"title": "Hello World"}
這個例子可以不直接工作:/
「從另一個文件」 - 你的意思是一個腳本運行在你的clojure應用程序之外(而不是應用程序中的一個javascript)? –
沒有在應用程序內部,而是一個服務器端文件。 – ehsun7b