Excuse me for my English. I'm a newbie in joomla. I make a phone book component and i wanna add a Ajax pagination. I've got Jquery function load_data where i put a url to my php page. And this is where i block.


// default.php
            // No direct access to this file
            defined('_JEXEC') or die('Restricted access');

            JHtml::_('stylesheet', JUri::root() . 'media/com_annuaire/css/annuaire.css');  // For CSS files
            JHtml::_('script', "//ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"); 
            JHtml::_('script', JUri::root() . 'media/com_annuaire/js/annuaire.js'); 

            $item = $this->item->loadObject();

            <div id="background-annuaire" style="background-image: url('<?php echo $item->background; ?>');">
                <div id="background-bloc">
                    <div id="bloc-annuaire">

                  function load_data(page)  
                  $(document).on('click', '.pagination_link', function(){  
                       var page = $(this).attr("id");  


    defined('_JEXEC') or die('Restricted access');

     $record_per_page = 5;  
     $page = '';  
     $output = '';  
          $page = $_POST["page"];  
          $page = 1;  

     $start_from = ($page - 1)*$record_per_page;  
     echo "1";

          $jinput = JFactory::getApplication()->input;
          $id     = $jinput->get('id', 1, 'INT');

          $db    = JFactory::getDbo();
          $query = $db->getQuery(true);
          $query->select('s.id as id,s.title,#__annucategories.title as category,annucatid,annuid,s.desc,s.address,s.numberphone,s.mail,s.city,s.place,#__annuairespoissy.background as background')
              ->from('#__servicespoissy AS s')
              ->leftJoin('#__annucategories on annucatid=#__annucategories.id')
              ->leftJoin('#__annuairespoissy on annuid=#__annuairespoissy.id')
              ->where('s.published = 1 AND annuid=' . (int)$id);
          $items = $db->loadObjectList(); 
          echo "2";

        foreach ($items as $row) : ?>
            <div class="bloc-service">
              <div class="category-annuaire"><?php echo $row->category; ?></div>
              <div class="category-title"><?php echo $row->title; ?></div>
              <span>En savoir plus</span>
              <div class="informations">
                <div class="category-desc"><?php echo $row->desc; ?></div>

                <div class="category-place"><img src ="/media/com_annuaire/images/place.png" alt="ico" style="float:left; padding-right: 5px;"><p><strong><?php echo $row->place; ?> - <?php echo $row->address; ?> - <?php echo $row->city; ?></strong></p></div>
                <div class="category-numberphone"><img src ="/media/com_annuaire/images/tel.png" alt="ico" style="float:left; padding-right: 5px;"><p><strong><?php echo $row->numberphone; ?></strong></p></div>
                <div class="category-mail"><img src ="/media/com_annuaire/images/mail.png" alt="ico" style="float:left; padding-right: 5px;"><p><strong><?php echo $row->mail; ?></strong></p></div>
          <?php endforeach; ?>

      echo "string";
     $total_records = $db->loadRowList();
     $total_pages = ceil($total_records/$record_per_page);  
     for($i=1; $i<=$total_pages; $i++)  
          $output .= "<span class='pagination_link' style='cursor:pointer; padding:6px; border:1px solid #ccc;' id='".$i."'>".$i."</span>";  
     $output .= '</div><br /><br />';  
     echo $output;  

As result, i've got 'Restricted access', so i try to remove 'defined('_JEXEC') or die('Restricted access');' from pagination.php, but my browser returns : "Failed to load resource: the server responded with a status of 500". I know i do something wrong but i don't know what. Someone to help me pls ? All my files are in the same directory.

  • You URL is incorrect. It should use the non-SEF version, like so: index.php?option=com_annuaire&....... Also make sure you don't import your own version of jQuery, but instead use JHtml::_('jquery.framework');. please take a look at this answer for help: joomla.stackexchange.com/a/147/168 – Lodder Apr 11 '18 at 14:47
  • @Lodder Thanks for the reply. I'm not sure to understand what i have to do. Should i create a subcontroller and put my code from pagination.php inside ? – Ronis Apr 12 '18 at 8:15
  • If you have found resolution for your question, please submit your discovery in a concise and educational manner so that future researchers can benefit from your toil. Once posted, please award your own answer the green tick so that this page is deemed resolved. – mickmackusa May 26 '18 at 22:10

Your Answer

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

Browse other questions tagged or ask your own question.