Using jQuery ajax: follow standard MVC Pattern

For Joomla! 2.5 Coding related discussions, please use: http://groups.google.com/group/joomla-dev-general
Note: All 1.6, 1.7 and 3.5 releases have reached end of life and should be updated to 3.x.

Moderator: ooffick

Forum rules
Please use the mailing list here: http://groups.google.com/group/joomla-dev-general rather than this forum.
Locked
rashidul_cse
Joomla! Apprentice
Joomla! Apprentice
Posts: 49
Joined: Mon May 10, 2010 11:02 am
Location: Bangladesh
Contact:

Using jQuery ajax: follow standard MVC Pattern

Post by rashidul_cse » Thu May 12, 2011 12:11 pm

Hi,

Hope everything goes well.

I'm developing a custom joomla 1.6 component. Based on user clicks on a tab I want to display some data through a jQuery Ajax call.

The name of the component is
com_pms
Here goes details.....
My jQuery Ajax code: executes/triggers when clicks on a button...

Code: Select all

$.ajax({
			type: 'POST',
		    url: 'index.php',
		    dataType: 'html',
		    data: 'option=com_pms&task=gcompose',
		    error: function(xhr, textStatus, errorThrown) {
		        alert('An error occurred! ' + errorThrown);
		    },
		    success: function(data, textStatus) {
		    	stopSpinner("pms_message_content_compose");
		        $(data).appendTo( '#pms_message_content_compose .no-table' );
		        lstate_compose = true;
		    }
		});
controller.php file contains..

Code: Select all

function gcompose(){
		JRequest::setVar( 'view', 'compose' );
	    JRequest::setVar( 'layout', 'form'  );
	    parent::display();
	}
views >> compose >> view.html.php

Code: Select all

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
 
// import Joomla view library
jimport('joomla.application.component.view');
 
class PmsViewCompose extends JView
{
	// Overwriting JView display method
	function display($tpl = null) 
	{
		// Display the view
		parent::display($tpl);
	}
}
views >> compose >> tmpl >> form.php

Code: Select all

<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
?>
<div>Some text</div>
I want to display "some text". But instead of this it displays the entire index.php where body contains "some text".

Any idea would be greatly appreciated.. :)

Thanks,
Rashidul
You do not have the required permissions to view the files attached to this post.

kballou
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 168
Joined: Mon Oct 08, 2007 10:51 pm

Re: Using jQuery ajax: follow standard MVC Pattern

Post by kballou » Thu May 12, 2011 7:33 pm

Include "tmpl=component" in the variables in your AJAX POST, or in your URL (as in "index.php?tmpl=component").

rashidul_cse
Joomla! Apprentice
Joomla! Apprentice
Posts: 49
Joined: Mon May 10, 2010 11:02 am
Location: Bangladesh
Contact:

Re: Using jQuery ajax: follow standard MVC Pattern

Post by rashidul_cse » Thu May 12, 2011 10:16 pm

kballou wrote:Include "tmpl=component" in the variables in your AJAX POST, or in your URL (as in "index.php?tmpl=component").
WOW. it does exactly what i want!!

Many thanks!


Locked

Return to “Joomla! 2.5 Coding”