我是AJAX和javascript的新手,但我正在尝试编写一些代码来删除表中的记录。这是我的代码:
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<script type="text/javascript">
$(function() {
$(".deletebutton").click(function(){
var record = $(this);
var del_id = record.attr("id");
var rec = 'id=' + del_id;
if(confirm("Are you sure you want to delete this Record?")){
$.ajax({
type: "POST",
url: "k.php",
data: rec,
success: function(){
}
});
$(this).parents(".record").animate({ backgroundColor: "#fbc7c7" }, "fast")
.animate({ opacity: "hide" }, "slow");
}
return false;
});
});
这里是php代码,它为行提供了一个id
echo '<td><div align = "left"><a href ="#" id="'.$row['id'].'" class = "deletebutton" title = "Delete">delete</a></div></td>';
由于某些原因,当我在javascript中打印出记录和del_id时,它们都是未定义的。