Картинка удалятся только после обновления страницы
Проблема в том что картинка удалятся только после обновления страницы а должна удался без обновления страницы с помощью ajax код js проверял в отдельном файле все работает в консоле одна ошибка.
$query_img = mysqli_query($link,"SELECT * FROM uploads_images WHERE products_id='$id'");
If (mysqli_num_rows($query_img) > 0)
{
$result_img = mysqli_fetch_array($query_img);
do
{
if (strlen($result_img["image"]) > 0 && file_exists("../uploads_images/".$result_img["image"]))
{
$img_path = '../uploads_images/'.$result_img["image"];
$max_width = 100;
$max_height = 110;
list($width, $height) = getimagesize($img_path);
$ratioh = $max_height/$height;
$ratiow = $max_width/$width;
$ratio = min($ratioh, $ratiow);
$width = intval($ratio*$width);
$height = intval($ratio*$height);
}else
{
$img_path = "./images/noimages.png";
$width = 90;
$height = 70;
}
echo '
<li id="del'.$result_img["id"].'" >
<img src="'.$img_path.'" width="'.$width.'" height="'.$height.'" title="'.$result_img["image"].'" />
<a class="del-img" img_id="'.$result_img["id"].'" ></a>
</li>
';
}while ($result_img = mysqli_fetch_array($query_img));
}
/////////
<?php
if($_SERVER["REQUEST_METHOD"] == "POST")
{
include("../include/db_connect.php");
$path = $_SERVER['DOCUMENT_ROOT']."/uploads_images/".$_POST["title"];
if (file_exists($path))
{
unlink($path);
$delete = mysqli_query($link,"DELETE FROM uploads_images WHERE id = '{$_POST["id"]}'");
echo "delete";
}
else
{
echo "delete";
$delete = mysqli_query($link,"DELETE FROM uploads_images WHERE id = '{$_POST["id"]}'");
}
}
?>
///////
$('.del-img').click(function(e){
e.preventDefault();
var img_id = $(this).attr("img_id");
var title_img = $("#del"+img_id+" > img").attr("title");
$.ajax({
type: "POST",
url: "./actions/delete-gallery.php",
data: "id="+img_id+"&title="+title_img,
dataType: "html",
cache: false,
success: function(data) {
if (data == "delete")
{
$("#del"+img_id).fadeOut(300);
}
}
});
})