Joomla 中的 jqquery-ias 不起作用


jqquery-ias in joomla doesn't work

我在joomla 3中有一篇文章,其中的php代码是这样的:

<?php
include(config.php);
$limit = 10; #item per page
# db connect
$link = mysql_connect(DB_HOST, DB_USER, DB_PASS) or die('Could not connect to MySQL DB ') .         mysql_error();
$db = mysql_select_db(DB_NAME, $link); 
$page = (int) (!isset($_GET['p'])) ? 1 : $_GET['p'];
# sql query
 $sql = "SELECT * FROM actor_info ORDER BY id DESC";
# find out query stat point
$start = ($page * $limit) - $limit;
# query for page navigation
if( mysql_num_rows(mysql_query($sql)) > ($page * $limit) ){
$next = ++$page;
}
 $query = mysql_query( $sql . " LIMIT {$start}, {$limit}");
if (mysql_num_rows($query) < 1) {
header('HTTP/1.0 404 Not Found');
echo 'Page not found!';
exit();
}
?>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="http://localhost/test/js/js/jquery-ias.min.js"></script>
<script type="text/javascript">
 $(document).ready(function() {
// Infinite Ajax Scroll configuration
jQuery.ias({
container : '#content', // main container where data goes to append
item: ".post",
pagination: "#content .navigation a",
next: ".next-posts a",
loader: '<img src="css/ajax-loader.gif"/>', // loading gif
triggerPageThreshold: 3 // show load more if scroll more than this
 });
});
</script>
</head>
<body>
<div class="wrap">
<h1><a href="#">Data load while scroll</a></h1>
 <!-- loop row data -->
<?php while ($row = mysql_fetch_array($query)): ?>
<div class="item" id="item-<?php echo $row['id']?>">
<h2>
<span class="num"><?php echo $row['id']?></span>
<span class="name"><?php echo $row['first_name'].' '.$row['last_name']?></span>
</h2>
<p><?php echo $row['film_info']?></p>
</div>
<?php endwhile?>
<!--page navigation-->
<?php if (isset($next)): ?>
<div class="nav">
 <div class="next-posts"><a href='test?p=<?php echo $next?>'>Next</a></div>
 </div>
<?php endif?>
 </div><!--.wrap-->
 </body>
</html>

现在它从数据库中检索数据,但是当我想观察滚动效果时,它会停止......所以它出现了一个链接"下一个",将我带到下一页/test?p=2 和更多

我该如何解决?

我通过一个名为SOURCERER的插件将此代码放在一篇文章中

你做错了。

混合代码和内容是一种不好的做法。但是在您的文章中混合老式 php 简直是疯了。

你试图违背框架而不是它。你让你的生活变得悲惨,你的代码丑陋和不可维护,你的网站容易受到攻击。每天你坚持这种方法,一只小猫就会死去。

所以你想要无限滚动吗?很好。 你的代码可以工作,我不熟悉IAS,但你需要把它移到其他地方(你需要迁移mysql_connect语句 - 你想使用JDatabase)并将初始化从:

<script type="text/javascript">
 $(document).ready(function() {

<script type="text/javascript">
 jQuery(document).ready(function() {

你的代码应该去哪里? 如果需要为要无限滚动到的每个页面重新调用它,则有以下几种选择:

  • 模板覆盖
  • 内容插件
  • 一个模块
  • 可以调用的专用控制器
  • 上述内容的组合(即初始调用的模板覆盖或模块,下一页结果的控制器)

可能模块可能是最简单的地方。 您的模块将被放置在文章内容正下方的位置,并且在初始加载后,通过参数确定请求是否是第二页的请求,并仅返回其标记(通过立即杀死 joomla 处理,一旦它到达模块)