Skip to content

Instantly share code, notes, and snippets.

@dukeofgaming
Created June 9, 2014 04:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dukeofgaming/9beed5e14d60a0cc2f3d to your computer and use it in GitHub Desktop.
Save dukeofgaming/9beed5e14d60a0cc2f3d to your computer and use it in GitHub Desktop.
AJAX in Joomla 1.5
<?php
/*
/com_mycomponent
|-/views
| |-/response
| |-/tmpl
| | |-default.php
| | |-index.html
| |-view.raw.php
*/
?>
<?php
//default.php
defined('_JEXEC') or die('Restricted access');
echo $this->response;
?>
<?php
//view.raw.php
defined('_JEXEC') or die('Restricted access');
jimport( 'joomla.application.component.view');
class MycomponentViewResponse extends JView{
public function plain($tpl=null){
$this->setLayout('default');
parent::display($tpl);
}
public function json($tpl=null){
$this->response = json_encode($this->response);
$this->setLayout('default');
parent::display($tpl);
}
}
?>
<?php
//somewhere in a controller
public function check(){
$view = &$this->getView('response','raw');
$view->response = 'OK';
$view->plain();
}
?>
In your ajax call use the following base URL:
index.php?option=com_mycomponent&format=raw&
Then append the right controller & task parameters to the url, like:
index.php?option=com_mycomponent&format=raw&controller=mycontroller&task=check
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment