Sign up to create your own snipts, or login.

Public snipts » dukeofgaming's snipts » AJAX in Joomla 1.5

posted on Jan 18, 2010 at 5:07 p.m. EST in 
  • <?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
    

    copy | embed

0 Comments

Sign up, or login to leave a comment.