ファイルを削除する前に確認したいのですが、確認のない私のコードは次のように機能します
<form action="delete.php" method="get">
<table>
<?php
foreach ($files as $file) {
?>
<tr>
<td><?php echo $fajl['file_name'];?></td>
<td><a href="delete.php?id=<?php echo $file['file_id'];?>"><img src="img/delete.png"/></a></td>
</tr>
<?php } ?>
</table>
</form>
delete.phpの一部
...if(isset($_GET['id'])){
$id = $_GET['id'];
$query = $pdo->prepare('DELETE FROM files WHERE file_id = ?');
$query->bindValue(1, $id);
$query->execute();
}
$files = $file->fetch_all();
...
削除をクリックすると、画像ファイルが削除されます。うまく機能しますが、ファイルを削除する前に確認したいと思います。私はゼブラダイアログでそれをやろうとしました私はclass = "delete"を追加します
<a href="delete.php?id=<?php echo $file['file_id'];?>"><img class="delete" src="img/delete.png"/></a>
そして次のコード
<script>
$(document).ready(function () {
$(".delete").bind("click", function (e) {
e.preventDefault();
var $this = $(this);
$.Zebra_Dialog("Do you want to delete this file?", {
type: "question",
title: "Are you sure?",
buttons: ['Yes', 'No'],
onClose: function (caption) {
if (caption == 'Yes') {
$.ajax({
url: 'delete.php',
data: {
id: $this.data('id'),
success: function(data){
alert("File deleted");
}
}
})
}
}
})
});
});
</script>
しかし、それは機能しません... PS 今、ゼブラダイアログにオプションがあることがわかりました
'buttons': [
{caption: 'Yes', callback: function() { alert('"Yes" was clicked')}},
{caption: 'No'},
]
代わりに
callback: function() { alert('"Yes" was clicked')}
電話する
delete.php?id=<?php echo $file['file_id']