问题描述
这是我用于删除记录的代码,但是删除成功完成后。
Waqas.notification("Data Deleted Successfully","success");
通知在页面顶部两次显示。
function DeleteUser(deleteid) {
$('#YesDelete').click(function() {
$.ajax({
url: "../Ajax/CrudSlider.php",
type: 'POST',
data: {
deleteid: deleteid
},
success: function(data) {
readRecords();
var split = data.split("::");
Waqas.notification("Data Deleted Successfully","success");
}
});
});
这是从数据库中删除记录的代码。
if(isset($_POST['deleteid']))
{
$user_id = $_POST['deleteid'];
$selectquery1="select * from slider where slider_id = $user_id";
$cm= mysqli_query($conn,$selectquery1);
$result =mysqli_fetch_array($cm);
$path = $result['slider_image'];
$deletequery = " DELETE FROM `slider` WHERE slider_id ='$user_id' ";
unlink($path);
if (!$result = mysqli_query($conn,$deletequery)) {
exit(mysqli_error());
}
}
这是删除模型。
单击DeleteUser()
。
<div class="modal Delete-modal">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Warning</h4>
</div>
<div class="modal-body">
<input type="hidden" id="DeleteHiddenID">
<div class="form-group">
<label for="Identification">Are You sure to delete the record.</label>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-success pull-right" data-dismiss="modal" id="YesDelete">Yes</button>
<button type="button" class="btn btn-danger" data-dismiss="modal" style="margin-right: 10px;">No</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div>
1楼
每次单击删除按钮时,都将单击事件绑定到YesDelete
按钮。
相反,您应该只分配一次事件,因此应将其移到DeleteUser
函数之外。
之后,您所需要做的就是更新发送到服务器的deleteid
。
最简单的方法是在调用DeleteUser
时将ID分配给全局变量。
然后,在调用服务器时,click事件将使用该ID。
例如
var deleteid;
$(function() {
$('#YesDelete').click(function() {
$.ajax({
url: "../Ajax/CrudSlider.php",
type: 'POST',
data: {
deleteid: deleteid
},
success: function(data) {
readRecords();
var split = data.split("::");
Waqas.notification("Data Deleted Successfully", "success");
}
});
});
});
function DeleteUser(id) {
deleteid = id;
}