Reputation: 461
Is is possible to handle ajax calls in Joomla without using a component helper?
For example; I want to create a module that makes ajax calls. I know how to handle the call using a component helper (index.php?option=com_myhelper....&format=raw), but instead of a component helper I would like to make this from the module.
Is there some way to call Joomla modules, the same way as you would call a Joomla component from an outside script (http://mydomain.com/index.php?option=com_myhelper....&format=raw) ?
Upvotes: 1
Views: 3199
Reputation: 791
Do you need to call an AJAX function from domainA to domainB? If so, you have to use a proxy.
What I did, maybe can help:
JS of the component:
J.ajax({
type: 'GET',
url: '/index.php',
data: {
option: 'com_mycomponent',
task: 'getTaskFromTheController',
param: 'paramValue1'
},
success: function(data) {
J('#suggestions').fadeIn();
J('#suggestions').html(data);
J('#suggestions .close-image').click(function() {
J('#suggestions').fadeOut();
});
}
More info about jQuery POST/GET
Add in the controller.php of the component the function getTaskFromTheController
public function getTaskFromTheController()
{
global $mainframe;
$model =& $this->getModel();
// If GET
// $param= JRequest::getVar('param');
// If POST
// $param = JRequest::getVar('param', '', 'post', 'string');
//Or
// $param = JRequest::getVar('param', '', 'post', 'string', JREQUEST_ALLOWHTML);
echo $model->getUserTaskAjax($param);
$mainframe->close();
}
Interesting links: http://forum.joomla.org/viewtopic.php?p=2424982 http://docs.joomla.org/Adding_AJAX_to_your_component How to use jQuery ajax in Joomla module
Upvotes: 1