使用 Google Closure 库的 Ajax 窗口(弹出)

发布于 11-24 06:44 字数 226 浏览 0 评论 0原文

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

  • goog.ui.Dialog 是实现此目标的合适类吗?
  • 我应该通过其他基本类(例如 good.net.XHRgoog.ui.Popup)来实现它吗?

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 good.net.XHR and goog.ui.Popup?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

左岸枫2024-12-01 06:44:16

您可以扩展 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"}

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

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 :/

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文