我正在創建圖書管理Web應用程序,並且在使用分頁時刪除圖書時出現問題。代碼點火器分頁和JQuery動作
在我的控制器我有這樣的代碼:
<?php
class Books extends CI_Controller {
function __construct()
{
parent::__construct();
#$this->load->model('books_model');
$this->load->helper('path');
}
function index() {
$config['base_url'] = base_url().'books/index';
$config['total_rows'] = $this->db->count_all('tbl_books');
$config['per_page'] = 2;
$this->pagination->initialize($config);
$data['books'] = $this->db->get('tbl_books',$config['per_page'], $this->uri->segment(3));
$data['pagination'] = $this->pagination->create_links();
$data['page'] = 'Books';
$this->load->view('books_view', $data);
}
}
?>
在我books_view我有這樣的代碼:
<p class="pagination ta-right">
<?=$pagination?>
</p>
<?php foreach($books->result() as $row): ?>
<a href="<?=base_url()?><?=$row->image?>" class="nyroModal"> <img src="<?=base_url()?><?=$row->image?>" alt="" /></a>
<a href="#<?=$row->id?>" title="<?=$row->title?>" class="nyroModal"><b class="big"><?=$row->title?></b></a> ·
<?php
$sql = $this->db->query("select * from tbl_transactions where bookid=".$row->id." and (type='reserve' or type='borrowed')");
$book_info = $sql->result();
if($sql->num_rows() > 0) {
if($book_info[0]->type == 'reserve') { ?>
<span class="label label-red">Reserved</span>
<?php }elseif($book_info[0]->type == 'borrowed') { ?>
<span class="label label-blue">Borrowed</span>
<?php } else { ?>
<span class="label label-green">Available</span>
<?php }
} else { ?>
<span class="label label-green">Available</span>
<?php } ?>
Author: <b><?=$row->authors?></b> | Category: </small><br/>
<div id="action-<?=$row->id?>">
<a href="" id="remove-<?=$row->id?>">remove</a> · <a href="#">edit</a>
</div>
<img src="<?=base_url()?>img/small-loader.gif" style="display:none;" id="ajax-load-<?=$row->id?>" />
<div id="<?=$row->id?>" style='display: none;'><h3><?=$row->title?></h3><p align="justify"><?=$row->description?></p></div>
<?php endforeach; } ?>
<script type="text/javascript">
$(document).ready(function() {
<?php foreach($books->result() as $row): ?>
$('#remove-<?=$row->id?>').click(function() {
var stats = confirm('Are you sure you want to delete this entry?');
if(stats) {
$('#action-<?=$row->id?>').hide();
$('#ajax-load-<?=$row->id?>').show();
$.ajax({
type: 'POST',
url: "<?=base_url()?>bookacts/delbook/",
data: ({id: <?=$row->id?>}),
cache: false,
success: function (msg){
if(msg == ""){
$('#ajax-load-<?=$row->id?>').hide();
$('.box-error').fadeIn("slow");
$('#action-<?=$row->id?>').fadeIn();
} else {
$('#ajax-load-<?=$row->id?>').hide();
$('.box-success').fadeIn("slow")
.animate({opacity: 1.0}, 2000)
.fadeOut('slow');
$('#action-<?=$row->id?>').fadeIn();
}
}
}); return false;
} else {
return false;
}
});
<?php endforeach; ?>
});
</script>
我的問題是,代碼只刪除該條目時,我第2頁向前。但是當我在第1頁時,腳本不起作用。