После того, как я нажму «Отменить» в окне предупреждения, удаление все еще происходит! Как я могу это решить? Я использую базу данных MySQL. Рабочего список тестов ToDo: http://qrmobile.net/todo/index.phpКак я могу отменить действие удаления с помощью окна подтверждения?
Удалить код ниже, а затем индекс кодовой страницы ...
НОВОГО КОД SNIPPET НИЖЕ: Аякс дает мне проблему?
// Delete entry
$('a.deleteEntryAnchor').click(function() {
var thisparam = $(this);
thisparam.parent().parent().find('p').text('Please hold your onions.... ☺');
$.ajax({
type: "GET",
url: thisparam.attr('href'),
success: function() {
thisparam.parent().parent().fadeOut('fast');
}
});
return false;
});
require 'db.php';
$db = new Db();
$response = $db->delete_by_id($_GET['id']);
header("Location: index.php");
<div id="container">
<header><img src="/todo/images/heading-trans.gif"></header>
<ul id="tabs">
<li id="todo_tab" class="selected">
<a href="#">To-Do</a>
</li>
</ul>
<div id="main">
<div id="todo">
<?php
require 'db.php';
$db = new Db();
$query = "SELECT * FROM todo ORDER BY id asc";
$results = $db->mysql->query($query);
if($results->num_rows) {
while($row = $results->fetch_object()) {
$title = $row->title;
$description = $row->description;
$id = $row->id;
echo '<div class="item">';
$data = <<<EOD
<h4>$title</h4>
<p>$description</p>
<input type="hidden" name="id" id="id" value="$id" />
<div class="options">
<a class="deleteEntryAnchor" href="delete.php?id=$id">Delete</a>
<a class="editEntry" href="#">Edit</a>
<a class="save-button" href="index.php">Save</a>
</div>
EOD;
echo $data;
echo '</div>';
} // end while
}
else {
echo "<p>There are zero items. Add one now! </p>";
}
?>
</div><!--end todo-->
<div id="addNewEntry">
<h2>Add New Entry</h2>
<form action="addItem.php" method="post">
<p><label for="title"> Title</label>
<input type="text" name="title" id="title" class="input" required/></p>
<p><label for="description"> Description</label>
<textarea name="description" id="description" required></textarea></p>
<p><input type="submit" name="addEntry" id="addEntry" value="Add New Entry" /></p>
</form>
</div><!--end addNewEntry-->
</div><!--end main-->
</div><!--end container-->
<script>
//Do all this when the DOM is loaded
$(function() {
//get all delete links (Note the class I gave them in the HTML)
$("a.deleteEntryAnchor").click(function() {
//Basically, if confirm is true (OK button is pressed), then
//the click event is permitted to continue, and the link will
//be followed - however, if the cancel is pressed, the click event will be stopped here.
return confirm("Are you sure you want to delete this?");
});
});
</script>