Very recently I have started programming and I'm currently running into an issue to which I hope you can help:
- Ajax executes the upload.php page which succesfully deletes the file from the server and from the MySQL table
- The Ajax result however is an error message and the image is not removed from Page.php unless reloaded.
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
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");
}
});
}