Ajax Window (Popup) Using Google Closure Library
Is there any class (like goog.ui.dialog
) that let me show a dialog which its content can be fetched by ajax from another file?
- Is goog.ui.Dialog an appropriate class for this goal?
- Shall I implement it by other fundamental classes such as
go开发者_开发问答od.net.XHR
andgoog.ui.Popup
?
You can extends the goog.ui.dialog and fetch the content.
A simple example wich can help you:
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);
That's use a response in json to build the ui.Dialog like this:
{"buttons": "goog.ui.Dialog.Buttons.OK_CANCEL",
"content": "<html><body><h1>Hello</h1></body></html>",
"title": "Hello World"}
This example can don't work directly :/
精彩评论