Programming in php: Zend ajax cant delete on newest questions tagged php – Stack Overflow

Hi i have a table name state with column state_id, state_name currently i can add and edit new state but i cant delete state..what might be wrong with my code…?

   {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}

this snippet is view, when i click deleteState js function ii will execute the following js script

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');
            }
        });

}

when i echo alert(countryDetail.state_id) before $.ajax call i can get the correct state id.

my delete controller is

    public function deleteAction()
{

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

}

and model mapper for delete is

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

}

where i might be wrong…??

See Answers


source: http://stackoverflow.com/questions/11572077/zend-ajax-cant-delete
Programming in php: programming-in-php



online applications demo