最近我开始编程,我目前遇到了一个问题,我希望你可以提供帮助:
page.php文件
<div class="row no-collapse 50% uniform">
<?php
while($row = mysqli_fetch_array($SubEntries_SQL)) {
$fileURL = "upload/" . $_SESSION['adminID'] . "/" . $row['filename'];
$fileId = $row['id'];
$fileName = $row['filename'];
if (!file_exists($fileURL)) { $fileURL = $sub_entryThumbURL = "../../images/no_img.png"; }
?>
<div class="2u" id="success">
<span class="image fit 50%">
<a href="javascript:void(0)" onclick="RemoveItem('<?=$fileId;?>','<?=$fileName;?>')">
<img src="<?=$fileURL;?>" border="0" class="thumb" />
</a>
</span>
</div>
<?php
}
?>
</div
Ajax功能
function RemoveItem(itemId,ItemName) {
$.ajax({
'url': 'content/upload.php',
'type': 'POST',
'data': {itemId: itemId, name: ItemName, request: 2},
'success': function(data) {
if (data == 1) {
$(".success").fadeIn(500).delay(2000).fadeOut(500);
}
},
'error': function () {
alert("error");
}
});
}
答案 0 :(得分:2)
一段时间内有一种混乱,这是我的建议:
假设您的$ fileId在所有节点中都是唯一的
<div class="2u delete_success" id="#delete_<?php echo $fileId; ?>">
通过这样做,您将获得不同的节点,下一步将是让您的javascript知道在完成后要删除的节点。
ajax函数就像是。
function RemoveItem(itemId,ItemName) {
$.ajax({
'url': 'content/upload.php',
'type': 'POST',
'data': {itemId: itemId, name: ItemName, request: 2},
'success': function(data) {
if (data == 1) {
$("#delete_"+itemId).fadeIn(500).delay(2000).fadeOut(500);
}
},
'error': function () {
alert("error");
}
});
}
更改了行:$("#delete_"+itemId).fadeIn(500).delay(2000).fadeOut(500);
这应该做的工作。
答案 1 :(得分:0)
非常感谢你指点我正确的方向!我用来获得所需结果的最终代码:
/ * jQuery * /
function RemoveItem(itemId,ItemName) {
$.ajax({
'url': 'content/upload.php',
'type': 'POST',
'data': {itemId: itemId, name: ItemName, request: 2},
'success': function(data) {
$("#delete_"+itemId).html( data );
/*$("#delete_"+itemId).fadeIn(500).delay(2000).fadeOut(500);*/
},
'error': function () {
alert("error");
}
});
/ * Html * /
<?php
while($row = mysqli_fetch_array($SubEntries_SQL)) {
$fileURL = "upload/" . $_SESSION['adminID'] . "/" . $row['filename'];
$fileId = $row['id'];
$fileName = $row['filename'];
if (!file_exists($fileURL)) { $fileURL = "../../images/no_img.png"; }
?>
<div class="2u" id="delete_<?php echo $fileId; ?>">
<span class="image fit 50%">
<a href="javascript:void(0)" onclick="RemoveItem('<?=$fileId;?>','<?=$fileName;?>')">
<img src="<?=$fileURL;?>" border="0" class="thumb_step1" />
</a>
</span>
</div>
<?php
}
?>
/ * upload.php * /
$targetDir = "upload/";
if($request == 2){
$filename = $targetDir.$_POST['name'];
mysqli_query($link, "DELETE FROM $upload_db WHERE filename = '".$_POST['name']."'");
unlink($filename);
}