Codeigniter jquery ajax 分页
我在这里得到一份教程 http://codeigniter.com/forums/viewthread/122597/P0/
一切都是找到但没有分页链接。
这是我的代码
<script>
ajax_paging = function()
{
$("p.pagination a").click(function()
{
$.ajax({
type: "GET",
url: $(this).get(),
success: function(html)
{
$("#display-content").html(html);
}
});
});
return false;
};
</script>
<?php
if($num_results == 0)
{
echo 'No data result, please insert one';
}
else
{
?>
<div id="display-content">
<table width="100%">
<tr>
<th>CP code</th>
<th>Code</th>
</tr>
<?php foreach($records as $row){ ?>
<tr>
<td align="center"><?php echo $row->created_date?></td>
<td align="center"><?php echo $row->uid?></td>
</tr>
<?php }?>
</table>
<p class="pagination">
<?=$pagination?>
</p>
</div>
<?php } ?>
,分页 HTML
<p class="pagination">
<strong>1</strong>
<a onclick="javascript:ajax_paging();return false;" href="http://bravonet.my/tombocrm/inside/home_fpr/5">2</a>
<a onclick="javascript:ajax_paging();return false;" href="http://bravonet.my/tombocrm/inside/home_fpr/10">3</a>
<a onclick="javascript:ajax_paging();return false;" href="http://bravonet.my/tombocrm/inside/home_fpr/5">></a>
</p>
当我尝试单击分页链接时,它的工作方式仅与普通链接相同。 javascript ajax 发生错误。
我的JavaScript很弱。如有任何帮助,我们将不胜感激,并提前致谢。
I get one tutorial over here
http://codeigniter.com/forums/viewthread/122597/P0/
everything is find but not the pagination link.
here's my code
<script>
ajax_paging = function()
{
$("p.pagination a").click(function()
{
$.ajax({
type: "GET",
url: $(this).get(),
success: function(html)
{
$("#display-content").html(html);
}
});
});
return false;
};
</script>
<?php
if($num_results == 0)
{
echo 'No data result, please insert one';
}
else
{
?>
<div id="display-content">
<table width="100%">
<tr>
<th>CP code</th>
<th>Code</th>
</tr>
<?php foreach($records as $row){ ?>
<tr>
<td align="center"><?php echo $row->created_date?></td>
<td align="center"><?php echo $row->uid?></td>
</tr>
<?php }?>
</table>
<p class="pagination">
<?=$pagination?>
</p>
</div>
<?php } ?>
here the pagination HTML
<p class="pagination">
<strong>1</strong>
<a onclick="javascript:ajax_paging();return false;" href="http://bravonet.my/tombocrm/inside/home_fpr/5">2</a>
<a onclick="javascript:ajax_paging();return false;" href="http://bravonet.my/tombocrm/inside/home_fpr/10">3</a>
<a onclick="javascript:ajax_paging();return false;" href="http://bravonet.my/tombocrm/inside/home_fpr/5">></a>
</p>
IWhen i try to click on the pagination link it works like normal link only. the javascript ajax occur error.
i am very weak in javascript. any help would be appreciated and thx in advanced.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
中添加 ajax 分页是如此简单
在 codeigniter标题
This is so easy to add ajax pagination in codeigniter
Heading
1 jquery .get() 用于获取 DOM 元素,因此您不需要在这里使用它,也不需要 $(this) 内的 $("p.pagination a").click() 引用标记,因此就像 r.piesnikowski 的评论中那样替换 $ (this).get() 和 $(this).attr('href')
2 不要将 onclick="javascript:ajax_pagin();return false;"在你的标签中,而不是在你的标签中留下这个片段(它将 onclick 事件处理程序添加到你的标签中):
3 在你的 js 代码中出现一个错误 - return false 放错了位置,并且 onclick 事件本身没有返回 false,ajax_pagin 却返回了 false,这就是链接正常工作的原因。
1 jquery .get() is for getting DOM elements so you don't need it here and $(this) inside $("p.pagination a").click() references tag, so like in r.piesnikowski's comment replace $(this).get() with $(this).attr('href')
2 Don't put onclick="javascript:ajax_pagin();return false;" in your tag, instead leave in your tag this snippet (which adds onclick event handler to your tags):
3 In your js code there was an error - return false was misplaced and the onclick event didn't return false itself, ajax_pagin did, that is why the link worked normally.