初次成功点击后,我似乎无法使下面的代码工作。我尝试了 $.post 和 ajax 都无济于事。删除任何项目的初始单击有效,但随后的单击无效
<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>
这是简单的 delthis.php 文件:
<?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;
?>
感谢任何帮助/指针。蒂亚!