gpt4 book ai didi

php - Zend Ajax无法删除

转载 作者:行者123 更新时间:2023-11-28 09:47:29 24 4
gpt4 key购买 nike

我有一个名为 state 的表,其中包含 state_idstate_name 列。目前我可以添加新状态并编辑它们,但无法删除状态。我的代码可能有什么问题?

{title:"Actions",template:'<a class="left" onclick="javascript:openEditStatePopup(this);">Edit</a>' + 
'<a class="right" onclick="javascript:deleteState(this);">Delete</a>'
,width:120,sortable:false}

此代码段是 View 代码,当我单击链接时,它会执行以下 JavaScript:

function deleteState(element)
{
var countryDetail = {};
var GriddataItem = $("#state_grid").data("kendoGrid").dataItem($(element).closest("tr"));
countryDetail.state_id =GriddataItem.state_id;
countryDetail.state_name = GriddataItem.state_name;
// alert(countryDetail.state_id);
$.ajax({
url:"<?= $this->baseUrl('admin/state/delete')?>",
data: {state_id : countryDetail.state_id},
dataType: "json",
type: "POST",
success: function(){
alert('success');
},
failure:function(){
alert('not working');
}
});
}

当我在 $.ajax 调用之前 echo alert(countryDetail.state_id) 时,我可以获得正确的州 ID。

我的删除 Controller 是:

public function deleteAction()
{

$state = $this->_request->_getPost('state_id');
$stateMapper = new Application_Model_Mapper_StateMapper();
$stateMapper->delete($state);
}

用于删除的模型映射器是:

public function delete(Application_Model_State $state)
{
$data = $state->toArray();
$adapter = $this->getDbTable()->getAdapter()->delete(array('state_id=?'=>$data['state_id']));
}

最佳答案

您好,您需要编写deleteAction如下

public function deleteAction()
{


$state = $this->_getParam('state_id');
$stateMapper = new Application_Model_Mapper_StateMapper();
$stateId = $stateMapper->delete($state);
$this->_helper->json(array('success'=>1));
}

关于php - Zend Ajax无法删除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11572077/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com