how to use Jquery AJAX in Joomla Components?

后端 未结 8 1668
野趣味
野趣味 2020-12-16 07:15

i m developing site in Joomla, meanwhile i stuck in a problem,please help me in below problem

here is my folder structure for component

htdocs/Joomla         


        
相关标签:
8条回答
  • 2020-12-16 07:18

    In joomla 1.7 and up you can close it like this

    $app = &JFactory::getApplication();
    $app->close();
    
    0 讨论(0)
  • 2020-12-16 07:23

    I found the solution. You must prevent the joomla to attach the templates and modules and ... to your output ajax data. for this you must add this code after displaying your data

    //after $this->display($tpl);
    
    global $mainframe;
    
    $mainframe->close();
    
    0 讨论(0)
  • 2020-12-16 07:26

    use format=raw in the ajax url, as this would just show the output without any template.

    0 讨论(0)
  • 2020-12-16 07:28

    1 - copy main index.php (joomlaRoot/index.php) of joomla and rename it to any name (for example: joomlaRoot/ajax.php).

    2 - disable render method ($mainframe->render();)

    3 - copy this code under the render method line:

    /***/
    $document =& JFactory::getDocument();
    $content=$document->getBuffer();
    foreach($content as $var){
        foreach($var as $var2){
            echo $var2;
        }
    }
    
    /**/
    
    0 讨论(0)
  • 2020-12-16 07:31

    All front end code should be in your tmpl, so your Ajax stuff should be in there too. Check this tutorial out on how to make MVC components for Joomla http://www.joomladevuser.com/tutorials/components (deadlink).

    0 讨论(0)
  • 2020-12-16 07:31

    That is right, Joomla will load modules, component, whatewer Your default template and Joomla core requires... Change this behavior by using "&format=raw" (this will force Joomla to include Joomla`s "nothing") or "&template=your_own_template_for_ajax" (this will force Joomla to include Your own "nothing").

    I didn`t knew about "&format=raw" so I use my own empty template for ajax. Empty tamplate makes sense for me - I can customize it the way I want (e.g. to include something by default). "&format=raw" is the good option, but not the only one. The decision depends on what You wanna do/get by default.

    How to make such ajax template in front-end?

    You must create a new directory (e.g. "ajax") inside front-end \templates\ directory. Then put 3 files inside:

    index.php:

    <jdoc:include type="component" />
    

    templateDetails.xml:

    ...XML content.. 
    

    Instructions on how to properly create templateDetails.xml can be found here:
    http://docs.joomla.org/Creating_a_basic_templateDetails.xml_file

    index.php:

    <!DOCTYPE html><title></title>
    

    That is all You need for the front-end solution.

    Test it by calling like this: http://www.example.com/index.php?template=ajax

    This is 100% working solution for the front-end. Back-end is not tested by me. I believe You would have to create a separate template for back-end also. Or reach the front-end template somehow (currently have no ideas on how to)...

    0 讨论(0)
提交回复
热议问题