我有一张图像列表,每个图像都有不同的ID。当用户单击<img>
“删除”按钮后的特定按钮时,我要<img>
删除该文件,同时还要从服务器中删除图像文件。我有以下ajax调用将实现此目的。
$(document).ready(function () {
$("img").click(function () {
var img_id = $(this).attr("id");
var imagefile = img_id;
img_id = "#" + img_id;
$("button").click(function () { // delete button
$("#image " + img_id).remove();
$("button").unbind();
$.ajax({
type: "POST",
url: "deleteimage.php",
data: imagefile,
success: function(response) {
// do something
}
});
});
});
我需要知道图像ID才能删除文件。因此,我将此传递给变量,然后将其发送到以下php文件。
<?php
include('config.php');
if(isset($_POST['imagefile']))
{
$imagefile = $_POST['imagefile'];
$imagepath = "Users/mp4_thumbnails-".$imagefile.".jpg";
unlink($imagepath);
}
?>
不幸的是,这不起作用。这是我第一次尝试ajax调用。任何输入将不胜感激。
试试这个
$.ajax({
type: "POST",
url: "deleteimage.php",
data: {"imagefile":imagefile},
success: function(response) {
// do something
}
});
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句