当前位置: 动力学知识库 > 问答 > 编程问答 >

php - AJAX request delete column base on their id.

问题描述:

Good day. I'm working on a admin page basically it is a content management system. I want to delete the data based on their id. But unfortunately i've encounter a error on the htpp request. here is the error.

Request URL: admin/ajax_delete

Request Method:POST

Status Code:500 Internal Server Error

Remote Address:144.76.136.165:8181

VIEW FILE:

<a href="#" data-target="" id="delete_tpi" class="edit-content-modal1" data-id="<?php echo $ds_content->id; ?>" value="<?php echo $ds_content->id; ?>"><span class="glyphicon glyphicon-trash"></span></a>

$("#delete_tpi").click(function() {

alert("Are you sure you want to delete?");

var tpi = $('.datatpi').val(); //package includes

var did = $('#data-id').val();

$.ajax({

url: '<?php echo site_url('admin/ajax_delete'); ?>',

type: 'POST',

datatype: 'html',

data: {id: did, tpi: tpi},

success:function (b){

if (b == 'Success') {

$('.#data-id').val('');

$('.datatpi').val('');

location.reload();

}

}

});

});

$('body').on('click','.edit-content-modal',function(){

var id = $(this).attr('data-id');

$('#data-id').val(id);

});

Controller file:

public function ajax_delete(){

$did = $this->input->post('id');

$ptpi = $this->input->post('tpi');

$update = $this->products_model->row_delete($did,$ptpi);

var_dump($update);

echo ($update)?'Success':'Fail';

}

MODEL FILE:

function ajax_delete($did,$ptpi){

$this->db->where('id',$did);

$this->db->delete('products',$ptpi);

return $this->db->affected_rows() > 0;

}

网友答案:

Because <a></a> element does not expect a value tag. You can get the ID of the clicked #delete_tpi link by using attr():

var did = $("#delete_tpi").attr('data-id');
网友答案:

Your POST request to admin/ajax_delete returns 500 Internal Server Error. This is a server-side error. If you use codeigniter, take a look at application/logs/*.log files that will give you detail information about the error.

I think, your problem is calling a non-existing function from model:

In your controller, you have:

$this->products_model->row_delete($did,$ptpi);

But your model, contains:

function ajax_delete($did,$ptpi){
    ....
}

Do you have row_delete() function in your model?

Once again, i suggest you to look at logs file, because many problems can result in server-side error.

分享给朋友:
您可能感兴趣的文章:
随机阅读: