Ajax窗口(弹出)使用谷歌关闭库

Ajax Window (Popup) Using Google Closure Library

本文关键字:谷歌 窗口 弹出 Ajax      更新时间:2023-09-26

是否有任何类(如goog.ui.dialog),让我显示一个对话框,其内容可以通过ajax从另一个文件获取?

    google .ui. dialog是一个适合这个目标的类吗?
  • 是否应该由good.net.XHRgoog.ui.Popup等其他基础类来实现?

您可以扩展google .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。对话框:

{"buttons": "goog.ui.Dialog.Buttons.OK_CANCEL", 
 "content": "<html><body><h1>Hello</h1></body></html>", 
 "title": "Hello World"}

这个例子不能直接工作:/