我需要在删除按钮中传递2个变量,但我不知道它为什么只传递一个变量。
下面是我的DELETE图标。
<a class="delete_employee" data-emp-id="<?php echo $row_dg["emp_id"]; ?>" data-usr-id="<?php echo $sessID; ?>" href="javascript:void(0)">
<i class="glyphicon glyphicon-trash"></i>
</a>
现在是AJAX请求
$(document).ready(function(){
$('.delete_employee').click(function(e){
e.preventDefault();
var empid = $(this).attr('data-emp-id');
var usrid = $(this).attr('data-usr-id');
var parent = $(this).parent("td").parent("tr");
bootbox.dialog({
message: "Are you sure you want to Delete ?",
title: "<i class='glyphicon glyphicon-trash'></i> Delete !",
buttons: {
success: {
label: "No",
className: "btn-success",
callback: function() {
$('.bootbox').modal('hide');
}
},
danger: {
label: "Delete!",
className: "btn-danger",
callback: function() {
$.ajax({
type: 'POST',
url: 'deleteRecords1.php',
data: 'usrid='+usrid+'&empid='+empid
})
.done(function(response){
bootbox.alert(response);
parent.fadeOut('slow');
})
.fail(function(){
bootbox.alert('Error....');
})
}
}
}
});
});
});
并在我的PHP文件下面更新记录。
<?php
if($_REQUEST['empid'] && $_REQUEST['usrid']) {
$sql = "UPDATE tbl_dies SET is_deleted='1', deleted_id='".$_REQUEST['usrid']."' WHERE emp_id='".$_REQUEST['empid']."'";
$resultset = mysqli_query($db, $sql) or die("database error:". mysqli_error($db));
if($resultset) {
echo "Record Deleted!";
}
}?>
所以,正如我所说,它只传递了一个变量,即empid和usrid缺失。
答案 0 :(得分:-1)
http://api.jquery.com/jQuery.ajax/
$.ajax({
method: "POST",
url: "some.php",
data: { name: "John", location: "Boston" }
})
注意这里如何处理“data:”。所以你的代码将是
$.ajax({
method: 'POST',
url: 'deleteRecords1.php',
data: { usrid: usrid, empid: empid }
})
希望它有所帮助。