As requested, here's a version that uses links instead of buttons.
<ol>
<li id="item-1">List item <a href="delete.php?1">Delete</a></li>
<li id="item-2">List item <a href="delete.php?2">Delete</a></li>
<li id="item-3">List item <a href="delete.php?3">Delete</a></li>
</ol>
And the JS support for this would be
$("ol").click(function(evt){
if (evt.target.nodeName != "A") {
return true;// it's not the delete link, so we don't have to do anything
}
var listItem = $(evt.target.parentNode);
if (listItem.hasClass("disabled")) {
return true;// we're still processing this already deleted list item
}
listItem.addClass("disabled");// lock the list item (perhaps visually too)
// set up the AJAX call
$.post("evaluator.php", {listId : listItem.attr("id")}, function(data){
// let's suppose that we get "1" if the user can perform the procedure
if (data == "1") {
// request approved, remove the list item
listItem.fadeOut("fast", function(){
$(this).remove();
});
} else {
// release the lock
listItem.removeClass("disabled");
// request denied, rollback
alert("Sorry, you can't do that.");
}
});
// here we stop the click event, so the URL in href won't be called.
// you can "disable" a link by returning false on a click event
// e.g. <a href="url" onclick="return false">disabled link</a>
return false;
});