在您的 zend 控制器中创建一个删除操作
<?php
public function deleteAction() {
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNoRender(true);
$request = $this->getRequest();
$id= $request->getPost('id');
/*
your code to delete the row from database using this id
when row deleted successfully then echo 'success' else echo 'failed'
*/
}
?>
现在来jquery ajax代码
<script type="text/javascript">
function deleteRow(id) {
var baseurl = '<?php echo baseUrl();?>';
$.ajax({
url: baseurl+"/delete/id/"+id,
type:'GET',
success:function(res){
if(res== 'success'){
alert("row deleted successfully");
} else {
alert("failed to delete row");
}
}
});
}
</script>
在删除按钮上调用 deleteRow 函数并在其中传递 id。