trying to delete a mysql database entry with ajax
I use ajax to show the database thusly:
while($row2 = mysql_fetch_assoc($result2))
{
echo "<div class=\"text\"><span>";
echo $row2['name'];
echo "</span><br/>";
}
echo "<b>";
echo $row['subject'];
echo "</b>";
echo "<br>";
echo $row['description'];
echo "<div class=\"date\">" . date("D, M y g:ia",strtotime($row['timestamp'])) . "</div>";
echo "</div>";
echo "<div class=\"clear\"></div>";
echo "<a href=\"?delete=";
echo $row['id'];
echo "\" class=\"delete\">Delete</a>";
echo "</div>";
but I'm having trouble deleting it.
I've tried putting this in the head, but it doesn't actually delete it...:
<script type="text/javascript">
$(document).ready(function() {
$('a.delet开发者_开发问答e').click(function(e) {
e.preventDefault();
var parent = $(this).parent();
$.ajax({
type: 'get',
url: 'delete.php',
data: 'ajax=1&delete=' + parent.attr('id').replace('record-',''), beforeSend: function() {
parent.animate({'backgroundColor':'#fb6c6c'},300);
}, success: function() {
parent.slideUp(300,function() {
parent.remove();
});
}
});
});
});
</script>
Any advice where to start?
Judging from the error you mentioned, I assume, you need to include JQuery before the javascript in the html head...
精彩评论