I can't seem to make the code below work after an initial successful click. I tried both $.post and ajax to no avail. The initial click to delete any of the items work, but the succeeding clicks do not work
<script>
$(document).ready(function(){
$('[id^="del"]').click(function(){
var valname = $(this).attr('id').split('del_');
/*$.post("delthis.php", {id: ""+valname[1]+""}, function(data) {
$("#dynamic_section").html(data);
});*/
$("#dynamic_section").load('delthis.php', {"id":valname[1]} );
return false;
});
});
</script>
<body>
<div id='static_section'>This is the static section</div>
<div id='dynamic_section' style='border: 1px solid black;'>
<?php
// db connection here
$sql = mysql_query("SELECT * from test_table ORDER BY id");
while ($row = mysql_fetch_array($sql))
{
?>
<p><a href='#' id='del_<?php echo $row['id']; ?>'>Hello <?php echo $row['id']; ?></a></p>
<?php
}
?>
</div>
This is the simple delthis.php file:
<?php
// db connection
//$id = $_POST['id'];
$id = $_REQUEST['id'];
$sql = mysql_query("DELETE from test_table WHERE id = '$id'");
$sql = mysql_query("SELECT * from test_table ORDER BY id");
while ($row = mysql_fetch_array($sql))
$html .= '<p><a href="#" id="del_' . $row['id'] . '">Hello ' . $row['id'] . '</a></p>';
echo $html;
?>
Appreciate any help/pointers. TIA!