{"id":2794,"date":"2013-04-26T17:17:48","date_gmt":"2013-04-26T08:17:48","guid":{"rendered":"http:\/\/www.lancard.com\/blog\/?p=2794"},"modified":"2025-03-12T11:29:02","modified_gmt":"2025-03-12T02:29:02","slug":"roudcube%e3%83%97%e3%83%a9%e3%82%b0%e3%82%a4%e3%83%b3%e3%81%a7ajax%e3%81%99%e3%82%8b","status":"publish","type":"post","link":"https:\/\/www.lancard.com\/blog\/2013\/04\/26\/roudcube%e3%83%97%e3%83%a9%e3%82%b0%e3%82%a4%e3%83%b3%e3%81%a7ajax%e3%81%99%e3%82%8b\/","title":{"rendered":"Roudcube\u30d7\u30e9\u30b0\u30a4\u30f3\u3067Ajax\u3059\u308b"},"content":{"rendered":"<p>Roudcube\u30d7\u30e9\u30b0\u30a4\u30f3\u3067Ajax\u3059\u308b\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002<\/p>\n<p>\u30b5\u30fc\u30d0\u5074\uff1a<\/p>\n<pre line=\"1\" lang=\"php\">\r\n<?php \r\nclass ajax_sample extends rcube_plugin {\r\n\r\nprivate $rc = null;\r\n\r\npublic function init(){\r\n$this->rc = rcmail::get_instance();\r\n\r\n$this->add_texts('localization\/');\r\n$this->register_task('ajax_sample');\r\n\r\nif($this->rc->task == 'ajax_sample'){\r\n$this->register_action('index', array($this, 'action'));\r\n$this->register_action('get_data', array($this, 'action'));\r\n}else{\r\n$this->add_button(array(\r\n'command' => 'ajax_sample',\r\n'label' => 'ajax_sample.title'\r\n), 'taskbar');\r\n}\r\n}\r\n\r\npublic function action(){\r\n\/\/\u753b\u9762\u8868\u793a\r\nif($this->rc->action === 'index'){\r\n\r\n$this->include_script('ajax_sample.js');\r\n$this->rc->output->send('ajax_sample.ajax_sample');\r\n\r\n\/\/ajax\r\n}else if($this->rc->action === 'get_data'){\r\n\r\nerror_log(get_input_value('data', RCUBE_INPUT_POST));\r\n$this->rc->output->command('plugin.get_data', array('data' => 'test'));\r\n\r\n}\r\n}\r\n\r\n}\r\n<\/pre>\n<p>\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\uff1a<\/p>\n<pre line=\"1\" lang=\"javascript\">\r\nvar get_data_call_back = function(response){\r\nconsole.log(response.data);\r\n}\r\n\r\nif (window.rcmail) {\r\nrcmail.addEventListener('init', function() {\r\nrcmail.addEventListener('plugin.get_data', get_data_call_back);\r\nrcmail.enable_command('get_data', true);\r\n});\r\n}\r\n\r\nrcube_webmail.prototype.get_data = function()\r\n{\r\nrcmail.http_post('get_data',{\"data\":'test'});\r\n}\r\n<\/pre>\n<p>\u2460\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u306e\u767b\u9332<br \/>\n\u3000\u3000\u30af\u30e9\u30a4\u30a2\u30f3\u30c8\u5074\u306ercmail.addEventListener(&#8216;plugin.get_data&#8217;, get_data_call_back);\u306e<br \/>\n\u3000\u3000\u7b2c\u4e00\u5f15\u6570\u3068<br \/>\n\u3000\u3000\u30b5\u30fc\u30d0\u5074\u306e$this->rc->output->command(&#8216;plugin.get_data&#8217;, array(&#8216;data&#8217; => &#8216;test&#8217;));\u306e<br \/>\n\u3000\u3000\u7b2c\u4e00\u5f15\u6570\u3092<br \/>\n\u3000\u3000\u4e00\u81f4\u3055\u305b\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<\/p>\n<p>\u3000\u3000\u3053\u306e\u969b\u306b&#8217;plugin.&#8217;\u3068\u3044\u3046\u6587\u5b57\u3092\u524d\u306b\u3064\u3051\u308b\u5fc5\u8981\u304c\u3042\u308a\u307e\u3059\u3002<br \/>\n\u3000\u3000\u306a\u305c\u306a\u3089\/roundcuberoot\/program\/include\/rcube_json_output.php\u306e<br \/>\n\u3000\u3000141\u884c\u76ee\u304c\u6b21\u306e\u3088\u3046\u306b\u306a\u3063\u3066\u3044\u307e\u3059\u3002<\/p>\n<pre line=\"1\" lang=\"php\">\r\n    public function command()\r\n    {\r\n        $cmd = func_get_args();\r\n\r\n        if (strpos($cmd[0], 'plugin.') === 0)\r\n          $this->callbacks[] = $cmd;\r\n        else\r\n          $this->commands[] = $cmd;\r\n    }\r\n<\/pre>\n<p>\u3000\u3000\u3053\u3053\u3067callbacks\u306b\u767b\u9332\u3055\u308c\u306a\u3044\u305f\u3081<\/p>\n<p>\u3000\u3000\/roundcuberoot\/program\/js\/app.src.js\u306e6041\u884c\u76ee<\/p>\n<pre line=\"1\" lang=\"javascript\">\r\n    \/\/ execute callback functions of plugins\r\n    if (response.callbacks && response.callbacks.length) {\r\n      for (var i=0; i < response.callbacks.length; i++)\r\n        this.triggerEvent(response.callbacks[i][0], response.callbacks[i][1]);\r\n    }\r\n<\/pre>\n<p>\u3000\u3000\u3053\u306e\u90e8\u5206\u306e\u30b3\u30fc\u30eb\u30d0\u30c3\u30af\u3068\u3057\u3066\u5b9f\u884c\u3055\u308c\u307e\u305b\u3093\u3002<\/p>\n<p>\u2461\u30dd\u30b9\u30c8\u3059\u308b\u30c7\u30fc\u30bf<br \/>\n\u3000\u3000rcmail.http_post('get_data',{\"data\":'test'});\u306e\u7b2c\u4e8c\u5f15\u6570\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<p>\u2462\u30b5\u30fc\u30d0\u304b\u3089\u8fd4\u3059\u30c7\u30fc\u30bf<br \/>\n\u3000\u3000$this->rc->output->command('plugin.get_data', array('data' => 'test'));\u306e\u7b2c\u4e8c\u5f15\u6570\u3067\u6307\u5b9a\u3057\u307e\u3059\u3002<\/p>\n<a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-facebook nolightbox\" data-provider=\"facebook\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Facebook\" href=\"https:\/\/www.facebook.com\/sharer.php?u=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F2794&#038;t=Roudcube%E3%83%97%E3%83%A9%E3%82%B0%E3%82%A4%E3%83%B3%E3%81%A7Ajax%E3%81%99%E3%82%8B&#038;s=100&#038;p&#091;url&#093;=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F2794&#038;p&#091;images&#093;&#091;0&#093;=&#038;p&#091;title&#093;=Roudcube%E3%83%97%E3%83%A9%E3%82%B0%E3%82%A4%E3%83%B3%E3%81%A7Ajax%E3%81%99%E3%82%8B\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"Facebook\" title=\"Share on Facebook\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/facebook.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-twitter nolightbox\" data-provider=\"twitter\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Twitter\" href=\"http:\/\/twitter.com\/share?url=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F2794&#038;text=Roudcube%E3%83%97%E3%83%A9%E3%82%B0%E3%82%A4%E3%83%B3%E3%81%A7Ajax%E3%81%99%E3%82%8B\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"twitter\" title=\"Share on Twitter\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/twitter.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-linkedin nolightbox\" data-provider=\"linkedin\" target=\"_blank\" rel=\"nofollow\" title=\"Share on Linkedin\" href=\"https:\/\/www.linkedin.com\/shareArticle?mini=true&#038;url=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F2794&#038;title=Roudcube%E3%83%97%E3%83%A9%E3%82%B0%E3%82%A4%E3%83%B3%E3%81%A7Ajax%E3%81%99%E3%82%8B\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"linkedin\" title=\"Share on Linkedin\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/linkedin.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-tumblr nolightbox\" data-provider=\"tumblr\" target=\"_blank\" rel=\"nofollow\" title=\"Share on tumblr\" href=\"https:\/\/tumblr.com\/share?s=&#038;v=3&#038;t=Roudcube%E3%83%97%E3%83%A9%E3%82%B0%E3%82%A4%E3%83%B3%E3%81%A7Ajax%E3%81%99%E3%82%8B&#038;u=https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F2794\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px;margin-right:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"tumblr\" title=\"Share on tumblr\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/tumblr.png\" \/><\/a><a class=\"synved-social-button synved-social-button-share synved-social-size-24 synved-social-resolution-single synved-social-provider-mail nolightbox\" data-provider=\"mail\" rel=\"nofollow\" title=\"Share by email\" href=\"mailto:?subject=Roudcube%E3%83%97%E3%83%A9%E3%82%B0%E3%82%A4%E3%83%B3%E3%81%A7Ajax%E3%81%99%E3%82%8B&#038;body=%E3%82%B7%E3%82%A7%E3%82%A2%E3%81%99%E3%82%8B%EF%BC%9A:%20https%3A%2F%2Fwww.lancard.com%2Fblog%2Fwp-json%2Fwp%2Fv2%2Fposts%2F2794\" style=\"font-size: 0px;width:24px;height:24px;margin:0;margin-bottom:5px\"><img loading=\"lazy\" decoding=\"async\" alt=\"mail\" title=\"Share by email\" class=\"synved-share-image synved-social-image synved-social-image-share\" width=\"24\" height=\"24\" style=\"display: inline;width:24px;height:24px;margin: 0;padding: 0;border: none;box-shadow: none\" src=\"https:\/\/www.lancard.com\/blog\/wp-content\/plugins\/social-media-feather\/synved-social\/image\/social\/regular\/48x48\/mail.png\" \/><\/a>","protected":false},"excerpt":{"rendered":"<p>Roudcube\u30d7\u30e9\u30b0\u30a4\u30f3\u3067Ajax\u3059\u308b\u65b9\u6cd5\u3092\u7d39\u4ecb\u3057\u307e\u3059\u3002 \u30b5\u30fc\u30d0\u5074\uff1a<\/p>\n","protected":false},"author":21,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[99],"tags":[],"class_list":["post-2794","post","type-post","status-publish","format-standard","hentry","category-roundcube"],"_links":{"self":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/2794","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/users\/21"}],"replies":[{"embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/comments?post=2794"}],"version-history":[{"count":9,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/2794\/revisions"}],"predecessor-version":[{"id":8222,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/posts\/2794\/revisions\/8222"}],"wp:attachment":[{"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/media?parent=2794"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/categories?post=2794"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.lancard.com\/blog\/wp-json\/wp\/v2\/tags?post=2794"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}