3

I am using the category layout to feature articles on my front page with joomla 3.3. I am customizing this view so that the article links pull the articles into this page via ajax on click.

This is the relevant code I customized :

HTML :

<h2 class="catView" data-link="<?php echo $this->item->link; ?> #k2Container">
    <?php if(isset($this->item->editLink)): ?>
</h2>

jQuery :

$('article.catView h2').click(function(){
    var link    = $(this).attr("data-link");
    $(this).parents().next('.artContainer').slideToggle(500).load(link);
});

This works, I manage to retrieve the data I need and display it correctly.

BUT

I am wondering if this is the correct way to do this, instead of retrieving an other page should I try to retrieve data straight from the data base? is there a "special joomla" way of doing this?

I would rather not rely on a third party extension for this and would like to control and understand this task.

  • I would recommend you use Joomla's built in Ajax component : docs.joomla.org/Using_Joomla_Ajax_Interface – Lodder May 20 '14 at 10:40
  • @Lodder thx for the suggestion, I'll dig into those docs – web-tiki May 20 '14 at 10:45
  • K2 supports JSON output so you may be able to do it without any additional extension. Take a look at getk2.org/blog/… – betweenbrain May 20 '14 at 14:54
  • We did this on a site for a client. I've sent your question to Jordan, he might be able to give you a hand. – Faye May 29 '14 at 22:44
2

http://jeffchannell.com/Joomla/load-the-joomla-framework-in-a-non-joomla-php-script.html

Using the above technique you can create an ajax.php file in the root directory and use the Joomla API's to call the data yourself from the database, then convert to JSON.

This will allow you to possibly use the k2 helpers to assist with it. Calling the database like this should only be used if you need a high level of customization.

betweenbrian makes a good point with this link http://getk2.org/blog/786-k2-v257-released-introduces-json-jsonp-content-output in that if k2 supports JSON, and it retrieves the data you need its probably perfect for what you need to do.

com_ajax does also come to mind, however it was built for modules/plugins. k2 itself is a component so it probably will not work as intended.

So in conclusion there is no "special Joomla" way to handle ajax, but there are many possibilities to get what you need done.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.