I am developing a Joomla component. Inside a frontend's view I've got a form with 2 drop lower menus by selecting a choice in the first, the choices from the second must change accordingly. To do this I am using AJAX.

I'm able to send the request towards the php function placed within the controller.php file and also the php function creates the right output.

However , Joomla framework put this output in the page with the meta data, header, web site and so forth as it ought to be proven around the browser before allow it to AJAX. You can observe a screenshot from firebug of the items I receive. The div where I wish to place the drop lower menu is -div id="choose-formatocarta"-, you can observe that prior to the "choose" I've a number of other undesirable things. http://img695.imageshack.us/img695/7725/selectp.jpg

As a result within the div where I wish to only place the "choose" menu produced through the php function, I recieve whole page. Even when I'm able to show the only real menu passing the tmpl=component parameter in the AJAX request, the div height is much like the entire page is within it.

How do i get the only php function's output with no Joomla template? If that is difficult, how do i extract the only real drop lower menu in the responseText? I'm able to just use javascript, I do not have prototype or jquery available.

Exit.

So Joomla will evaluate your component code first, adding the header/footer through the templates system later (for this reason components dynamically can also add header lines for CSS etc). So all that you should do is exit immediately, preventing Joomla from having the ability to add the header/footer.

So inside your controller code, you'd have something similar to:

<?php

function ajax_foo()
{
    ...code here...
    $view->display();
    jexit();
}

The built-in PHP exit() function would work fine, but jexit() is preferred.

You have to produce a sub controller inside your /components/com_yourcomponent/remotes/ folder known as ajax.raw.php

After that you can send ajax demands into it such as this:

index.php?option=com_title&task=ajax.function_title&format=raw&var=value

  • The "function_title" will perform function of the identical title within the controller.
  • The format=raw informs joomla to not range from the template
  • The var=value signifies any parameters you want to send and may be retrieved using JRequest::getVar()

It's not necessary to produce a new controller with this. You can just make use of your existing controller and append &format=raw towards the URL. That switches off all output by Joomla. Developing a special controller for that ajax call is simply something that may be sound practice just in case your component is large and hard to keep otherwise.

Using jexit() only to supress the output is completely bad.