我实际上需要删除在codeigniter中通过ajax检查的多行。 当我点击删除按钮它给我所有选中的复选框的值,但它没有将所有值传递给控制器,因此只有最后检查的值得到deletd请帮助我..
查看页面...
时调用javascript<div class="multiple_del" title="Delete"><img src="../../images/minus.png"/></div>
</div>
单击
<table border="0" cellpadding="0" style="width:100%;margin:0px auto" cellspacing="0" id="product-table">
<thead>
<tr>
<th class="tbl_hdr sorter-false"><img src="../../images/trash.png" style="padding-left:13px;"/></th><!--Multiple Delete--->
<th class="tbl_hdr">USER ID</th> <!--ID-->
<th class="tbl_hdr">NAME</th> <!--Name-->
<th class="tbl_hdr">EMAIL</th> <!--Email-->
<th class="tbl_hdr">PHONE NUMBER</th> <!--ph number-->
<th class="tbl_hdr sorter-false">STATUS</th> <!--publish/unpublish-->
<th class="tbl_hdr sorter-false" colspan="2">ACTION</th> <!--edit/delte-->
</tr>
</thead>
<tbody>
<?php
$count=1;
foreach($users as $user){
if($count%2==0){?>
<tr class="alternate-row"><?php }?>
<td><input type="checkbox" name="checkboxlist" value="<?php echo $user->id;?>"/></td>
<td><?php echo $user->id;?></td>
<td><?php echo $user->username;?></td>
<td><?php echo $user->email;?></td>
<td><?php echo $user->contact;?></td>
<?php if ($user->status==0)
{?>
<td>
<div align="center">
<a class="status unpublished" value="<?php echo $user->id;?>" title="Unpublished"></a>
</div>
</td>
<?php }
else
{?>
<td>
<div align="center">
<a class="status published" value="<?php echo $user->id;?>" title="Published"></a>
</div>
</td>
<?php }?>
<td>
<a class="editbutton"><span class="edit editbutton" title="Edit"><img src="../../images/edit.png"/></span></a>
<a class="removebutton" onclick="deleteuser('<?php echo $user->id;?>')"><span class="delete removebutton" title="Delete"><img src="../../images/delete.png"/></span></a>
</td>
</tr>
<?php $count++;}?>
</tbody>
</table>
<div>
<div class="multiple_del" title="Delete"><img src="../../images/minus.png"/></div>
</div>
...的Javascript
$(document).ready(function(){
$('.multiple_del').click(function(){
var checkValues = $('input[name=checkboxlist]:checked').map(function()
{
return $(this).val();
}).get();
//alert(checkValues);
var url='<?php echo base_url(); ?>index.php/admin/delete_multiple';
$.ajax({
type: 'POST',
url: url,
data: { ids: checkValues },
success:function(data)
{
window.location="<?php echo base_url(); ?>index.php/admin/users";
$( ".msg1" ).text( "Selected Users Deleted..!!");
}
});
});
});
控制器... ajax网址转到此控制器
public function delete_multiple()//Delete Multiple Users
{
$ids=$this->input->post('ids');
$this->admin_model->delete_multiple($ids);
}
...模型
function delete_multiple($ids)//Delete Multiple Users
{
$this->db
->where_in('id', $ids)
->delete('tbl_users');
}