Author |
|
iSofia Newbie
Joined: 24 May 2014 Location: Singapore
Online Status: Offline Posts: 35
|
Posted: 16 October 2014 at 8:16am | IP Logged
|
|
|
The AJAX plugin example clearly demonstrates how to receive data via AJAX:
Code:
AfterLogicApi.sendAjaxRequest({'Action': 'GetData'}, function (oData)... |
|
|
How would we go about sending data through this AJAX method?
Thank you.
|
Back to Top |
|
|
iSofia Newbie
Joined: 24 May 2014 Location: Singapore
Online Status: Offline Posts: 35
|
Posted: 16 October 2014 at 11:59pm | IP Logged
|
|
|
I found this in the manual, and it seems like just the ticket, but I don't know how to use it.
JavaScript API (WebMail):
-> Client-side API Hooks
--> AfterLogicApi.addPluginHook function (ajax-default-request)
I'm assuming that the syntax might be something like this:
Code:
AfterLogicApi.addPluginHook(
{
'ajax-default-request', 'my additional data'
});
|
|
|
But how would the data be received by the class in index.php?
Please help. Thank you.
|
Back to Top |
|
|
Igor AfterLogic Support
Joined: 24 June 2008 Location: United States
Online Status: Offline Posts: 6104
|
Posted: 17 October 2014 at 2:57am | IP Logged
|
|
|
AfterLogicApi.sendAjaxRequest() function can accept arbitrary number of parameters submitted as follows:
Code:
oParameters = {
'Action': 'ActionValue',
'Parameter1': 'Parameter1Value,
...
} |
|
|
Action parameter is the only one mandatory there.
As for adding ajax-default-request hook, it's done as follows:
Code:
AfterLogicApi.addPluginHook('ajax-default-request', function (sAction, oParameters) {
// this code will be run every time any AJAX request is going through
}); |
|
|
Hope this helps!
--
Regards,
Igor, AfterLogic Support
|
Back to Top |
|
|
iSofia Newbie
Joined: 24 May 2014 Location: Singapore
Online Status: Offline Posts: 35
|
Posted: 17 October 2014 at 3:16am | IP Logged
|
|
|
Hi Igor. Thank you so much for your answer. Hope you're still there!
Once the parameters are passed to the class in index.php, how does the function read it?
Please help.
|
Back to Top |
|
|
Igor AfterLogic Support
Joined: 24 June 2008 Location: United States
Online Status: Offline Posts: 6104
|
Posted: 17 October 2014 at 3:37am | IP Logged
|
|
|
You can obtain parameter value by its name as follows:
Code:
$this->oPluginManager->Actions()->getParamValue('parameter_name_here', 'default_value_here'); |
|
|
For example, if you're sending information about user's gender, that would be something like this on server side:
Code:
$sUserGender = $this->oPluginManager->Actions()->getParamValue('user_gender', ''); |
|
|
Hope this makes sense ;)
--
Regards,
Igor, AfterLogic Support
|
Back to Top |
|
|
iSofia Newbie
Joined: 24 May 2014 Location: Singapore
Online Status: Offline Posts: 35
|
Posted: 17 October 2014 at 3:51am | IP Logged
|
|
|
Igor wrote:
You can obtain parameter value by its name as follows:
Code:
$this->oPluginManager->Actions()->getParamValue('parameter_name_here', 'default_value_here'); |
|
|
For example, if you're sending information about user's gender, that would be something like this on server side:
Code:
$sUserGender = $this->oPluginManager->Actions()->getParamValue('user_gender', ''); |
|
|
Hope this makes sense ;) |
|
|
It makes perfect sense, although it's not something that I would have figured out myself; EVER.
I don't believe that this is documented, and I'm sure that it would prove to be very helpful to many.
I sincerely thank you, Igor. You've made my day, and my weekend!
Just my tears of joy!
|
Back to Top |
|
|
Igor AfterLogic Support
Joined: 24 June 2008 Location: United States
Online Status: Offline Posts: 6104
|
Posted: 17 October 2014 at 4:00am | IP Logged
|
|
|
Good point, thank you. I'll make sure our docs team will take care of that, and maybe there will be a separate sample plugin demonstrating use of custom parameters.
--
Regards,
Igor, AfterLogic Support
|
Back to Top |
|
|
iSofia Newbie
Joined: 24 May 2014 Location: Singapore
Online Status: Offline Posts: 35
|
Posted: 17 October 2014 at 4:03am | IP Logged
|
|
|
Igor wrote:
Good point, thank you. I'll make sure our docs team will take care of that, and maybe there will be a separate sample plugin demonstrating use of custom parameters. |
|
|
That sounds great! Thanks again.
|
Back to Top |
|
|