From jakob-b@posteo.de Mon Sep 12 11:21:36 2016 From: Jakob Bachhuber To: dev@lists.roundcube.net Subject: [RCD] Plugin - AJAX GET request to cross domain Date: Mon, 12 Sep 2016 19:21:25 +1000 Message-ID: In-Reply-To: <4ae2463a-baf5-95df-cfac-11257106a2b8@posteo.uk> MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============4607232562142138847==" --===============4607232562142138847== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Hey all, I am developing a plugin, where I wanna ask my personal web API about some email details. First, I tried to make a jquery ajax request. Firebug shows me the correct response, but I always get a 404 error. So the plugin does not get the result. I can imagine that is because a cross domain issue. Then I tried to do an ajax request to my server side plugin code, where I would try to make a php request to my API. But to be honest, I can't figure out how to send my values with such a GET request, process them within the php function and send it back. Of course, I have read the documentation. I also analysed some other plugins, but it is still just random guessing for me. Thanks for any help. Cheers, Jack In my JavaScript I do: var value = "test" rcmail.http_get("plugin.someaction","value"+value); In my php I do: $this->register_action('plugin.someaction', array($this, 'actions')); and function actions($args) { echo ''; echo ''; $this->rc->ouput->send(); } --===============4607232562142138847== Content-Type: application/pgp-signature Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename="signature.asc" MIME-Version: 1.0 LS0tLS1CRUdJTiBQR1AgU0lHTkFUVVJFLS0tLS0KVmVyc2lvbjogR251UEcgdjIKCmlRRWNCQUVC Q0FBR0JRSlgxbk9hQUFvSkVFdUEzcWViRHFBR2NrNEgvMEV4RXhVUitFODUwN0JOMklvZGlFSTEK VmN4TGtEMytxVXFJR25aNzFydHVBRmoxSUFuY3JrRFFWWkpKemlKMi9RUzFWOHBHMnprSGdHV0p3 MVNiRmZ3OAp2T1Vrb2tJLzNjTWZCM0ZnMThMLzBEVWV2RDhZWTJFSnZuWGtON2JBVThNSkJFb1lt M1FNZ3VROHpCczZwQVdYCmhHNDlteG41WENteW9kTWlmT1lpME9nWHVlNnMrK0UvWWJ6bUpaVWZ5 Tk9VdG14NWV4MmJaTkRNYjZ2UlMwRTkKMXZtc0dXUll5aURYczhuSzZlZE1zMEdSUUpzVzRXa2dD NXVwQVZVWHRFdW1tMUN0ekszRVF5S1dWMXNQTnp3TwoyRmdKTkdUWUFUbjBoUXg1eTNxU1VaVVpH YmViVU1wUmdwUWI0TTJaNk9sZWwrMjcwMFk2VU1Xai9PMlhwbEE9Cj1WMklzCi0tLS0tRU5EIFBH UCBTSUdOQVRVUkUtLS0tLQo= --===============4607232562142138847==-- From thomas@roundcube.net Fri Sep 16 16:56:26 2016 From: Thomas Bruederli To: dev@lists.roundcube.net Subject: Re: [RCD] Plugin - AJAX GET request to cross domain Date: Fri, 16 Sep 2016 16:56:22 +0200 Message-ID: In-Reply-To: MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="===============6135174942086524612==" --===============6135174942086524612== Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable On Mon, Sep 12, 2016 at 11:21 AM, Jakob Bachhuber wrote: > [...] > > Of course, I have read the documentation. I also analysed some other > plugins, but it is still just random guessing for me. The relevant part for you is probably here: https://github.com/roundcube/roundcubemail/wiki/Plugin-API#ajax-requests-and-= callbacks > In my php I do: > $this->register_action('plugin.someaction', array($this, 'actions')); > > and > > function actions($args) > { > echo ''; > echo ''; > $this->rc->ouput->send(); > } The way to pass data back to the client is not using `echo` but send it a "command" for which your plugin has already registered an event listener: $rcmail->output->command('plugin.somecallback', $args); Makes sense? ~Thomas --===============6135174942086524612==--