尝试使用ajax删除mysql数据库条目

时间:2011-07-25 09:02:01

标签: php jquery mysql ajax

我使用ajax来显示数据库:

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>";

但是我无法删除它。

我已经尝试过将它放在头部,但实际上并没有将其删除......:

    <script type="text/javascript">
$(document).ready(function() {
  $('a.delete').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>

任何建议从哪里开始?

1 个答案:

答案 0 :(得分:1)

从您提到的错误来看,我认为,您需要在html头部的javascript之前包含JQuery ...