Created
June 9, 2014 04:17
-
-
Save dukeofgaming/9beed5e14d60a0cc2f3d to your computer and use it in GitHub Desktop.
AJAX in Joomla 1.5
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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