这是我第一次尝试使用 Ajax 和 PHP 从 MySQL 中删除一行。我收到错误:
PHP 致命错误:在第 10 行的 /home/insightd/public_html/dev/wp-content/plugins/id-ffui/lib/delete.php 中的非对象上调用成员函数 delete()
一切正常,但该行没有删除。
HTML 表单的删除部分:
echo "<div class='ffui-media-item'>";
echo "<div class='ffui-delete' align='center'><a href='#' id='" . $media_item['ID'] . "' class='delbutton' title='Click To Delete'>X</a></div>";
jQuery/Ajax 部分:
<script type="text/javascript">
$(function() {
$(".delbutton").click(function(){
//Save the link in a variable called element
var element = $(this);
//Find the id of the link that was clicked
var del_id = element.attr('id');
//Built a url to send
var info = {"id" : del_id };
if(confirm("Are you sure you want to delete this Record?")) {
$.ajax({
type: "POST",
url: "<?php echo plugins_url('id-ffui/lib/delete.php') ?>",
data: info,
success: function(){
}
});
$(this).parents(".ffui-media-item").animate({ backgroundColor: "#fbc7c7" }, "fast")
.animate({ opacity: "hide" }, "slow");
}
return false;
});
});
</script>
和 delete.php 文件:
global $wpdb;
global $ffui_db_version;
$ffui_items = $wpdb->prefix . "ffui_items";
if($_POST['id']) {
$id = $_POST['id'];
$wpdb->delete( $ffui_items, array( 'ID' => `$id` ) );
}
任何帮助将不胜感激。提前致谢。