I have code like this:
$(".delete").click(function() {
var commentContainer = $(this).parent();
var id = $(this).attr("id");
var string = 'id='+ id ;
$.ajax({
url: "<?php echo site_url('admin/delete_admin') ?>",
type: "POST",
data: string,
cache: false,
error: function(){
$(this).parent().append('You can not delete admin. Please contact main admin .');
},
success: function(){
commentContainer.slideUp('slow', function() {$(this).remove();});
}
});
return false;
});
and PHP:
function delete_admin()
{
$q = $this->admin_model->get_admin();
if($q->privilege == 'main_admin')
{
$this->admin_model->delete_admin( $_POST['id']);
}
else
{
return false;
}
}//end of delete_admin
How to send message that user can’t do delete? Function is working like it is success every time (container is sliding).
The response data is sent to the
successcallback function, so you can pick it up and check the value.If you return the string “ok” for success: