I googled data.success, but I could not proper document. What is data.success in the following jquery? Is it javascript, jquery or json?
function remove_row(data){
if(!data.success)
return alert(data.error);
$('#delete_link_'+data.id)
.closest('li')
.slideUp('slow',function(){
$(this).remove();
});
--Edit--
Full jquery
$(document).ready(subscribers_init);
function subscribers_init(){
$('#subscribers li a:first-child')
.click(delete_subscriber);
}
function delete_subscriber(){
var id=this.href.replace(/.*=/,'');
this.id='delete_link_'+id;
if(confirm('Are you sure you want to delete this subscriber?'))
$.getJSON('delete.php?ajax=true&id='+id, remove_row);
return false;
}
function remove_row(data){
if(!data.success)
return alert(data.error);
$('#delete_link_'+data.id)
.closest('li')
.slideUp('slow',function(){
$(this).remove();
});
}
--Edit 2--
delete.php
$id=(int)@$_REQUEST['id'];
echo ( !($id%2) )?
"{'id':$id,'success':1}":
"{'id':$id,'success':0,'error':'Could not delete subscriber'}";
HTML
<ul id="subscribers">
<li>
<a href="delete.php?id=3">[x]</a>
<a href="user.php?id=3">Albertus Ackleton</a>
</li>
<li>
<a href="delete.php?id=6">[x]</a>
<a href="user.php?id=6">Bob Burry</a>
</li>
...
...
</ul>