Function:
<script> function clearLogs() { if (confirm("Вы уверены, что хотите удалить логи сервера?")) { <?php if($server['server_status'] == 1): ?> <?php if(isset($_POST['btnClear'])){ unlink("путь к файлу");} ?> $.jGrowl("Логи успешно удалены!", { sticky: !1, position: "top-right", theme: "bg-green" }); //setTimeout("redirect('/servers/serverLogs/index/<?php echo $server['server_id'] ?>')", 1500); <?php elseif($server['server_status'] == 2): ?> $.jGrowl("Логи нельзя удалить на включенном сервере!", { sticky: !1, position: "top-right", theme: "bg-red" }); <?php elseif($server['server_status'] == 0): ?> $.jGrowl("11111", { sticky: !1, position: "top-right", theme: "bg-red" }); <?php elseif($server['server_status'] == 4): ?> $.jGrowl("22222", { sticky: !1, position: "top-right", theme: "bg-red" }); <?php endif; ?> return false; } else { return false; } } </script> If the function above is called in this way:
<form method='post'> <button type="submit" class="btn btn-danger" name="btnClear" id="btnClear" onclick="clearLogs();">Очистить лог</button> </form> That, removal of logs works, BUT the page automatically reloads.
If called in this way:
<form method='post'> <button type="submit" class="btn btn-danger" name="btnClear" id="btnClear" onclick="return clearLogs();">Очистить лог</button> </form> The page is not updated, but does not delete the logs!
Tell me, please, what is the matter.


htmlwithoutphp, which sendsajax запросtophp, which in turn will givejsonanswer. - Artem Gorlachev