I'm having a minor but rather annoying issue with a webpage I'm making. So I have a link that, when clicked, makes an AJAX request to a PHP script (the link sends a hidden input value, if that matters). It works fine and it works as I expect, but then if I try to click the link again, it doesn't do anything. I have to refresh the page in order for it to work again, and I prefer to not have to do this.
Link:
<a name='delete-link' href='#'>Delete</a>
JavaScript:
$("a[name='delete-link']").click(function(e){
e.preventDefault();
var ID = $(this).parents("ul").find("input[name='delete-identifier']").val();
$.ajax({
type: 'POST',
url: '../ajax.php',
data: {delete: 'true', delete_id: ID},
success: function(response){
$("#result").html(response).fadeIn(500).delay(5000).fadeOut(500);
$("div[name='update']").load("test.php #update");
}
})
})
The only code in the #update div is this PHP code which echoes a table displaying users:
<?php
if ($rs){
$user_table = "<table class='table table-bordered table-condensed table-hover table-striped'><th>Action</th>";
$user_table .= "<tr><th>Name</th><th>Privilege ID</th></tr>";
while ($user = $rs->fetch_array(MYSQL_ASSOC)){
$user_table .= "<td>". $rank['RankName'] ."</td><td>". $user['PrivilegeID'] ."</td><td>";
$user_table .= "<td><div class='btn-group'>
<button type='button' class='btn btn-default dropdown-toggle' data-toggle='dropdown' aria-expanded='false'>
Action <span class='caret'></span>
</button>
<ul class='dropdown-menu' role='menu'>
<input type='hidden' name='delete-identifier' value='". $user['ID'] ."'>
<li><a name='delete-link' href=''>Delete</a></li>
</ul>
</div>
</td><tr>";
}
$user_table .= "</table>";
echo($user_table);
}
?>
Any ideas?