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.
(Updated)
// 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">
</div>
</div>
</div>
<script>
$(document).ready(function(){
load_data();
function load_data(page)
{
$.ajax({
url:"/components/com_annuaire/views/annuaire/tmpl/pagination.php",
method:"POST",
data:{page:page},
success:function(data){
$('#bloc-annuaire').html(data);
}
})
}
$(document).on('click', '.pagination_link', function(){
var page = $(this).attr("id");
load_data(page);
});
});
</script>
//pagination.php
defined('_JEXEC') or die('Restricted access');
$record_per_page = 5;
$page = '';
$output = '';
if(isset($_POST["page"]))
{
$page = $_POST["page"];
}
else
{
$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);
$db->setQuery((string)$query,$record_per_page,$start_from);
$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>
</div>
</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.
index.php?option=com_annuaire&......
. Also make sure you don't import your own version of jQuery, but instead useJHtml::_('jquery.framework');
. please take a look at this answer for help: joomla.stackexchange.com/a/147/168 – Lodder Apr 11 '18 at 14:47