我的Web应用程序中有一个按钮。当用户单击它时,我想要求确认并在数据库中执行一些活动。
我已经使用bootstrapconfirmation.js编写了代码。当用户单击该按钮时,数据库中的一行将变为活动/不活动状态。当我第一次单击时,它可以正常工作,但是在下次单击时,它无法正常工作。
在调试时,我有一个名为value3
的变量。当我alert
开头时,它显示一个适当的值,但是当我alert
时,它在AJAX中给我一个先前的值(当它正常工作时)。它没有改变。可能是什么问题?
<button type="button" class="active_inactive" data-category="<%=resultSet.getString(" category_id ")%>" value="Deactivate" onclick="process(this, '<%=resultSet.getString(" category_id ")%>', 'active_inactive', this.value)" title="Deactivate"><i class='fa fa-times'></i></button>
function process(thisobj, id, button_id, button_value) {
var value, value1, value2, value3;
if (button_value === "Activate") {
value = "activation";
value1 = "Activation";
value2 = "activate";
value3 = "Active";
} else {
value = "de-activation";
value1 = "De-activation";
value2 = "de-activate";
value3 = "Inactive";
}
alert(value3);
$.ajax({
url: '../Category',
context: thisobj,
data: {
"mode": "checkwarning",
"category_id": id
},
dataType: "html",
contentType: "application/json",
type: 'GET',
success: function() {
$(thisobj).confirmation({
container: 'body',
placement: 'top',
btnOkLabel: 'Confirm',
title: 'Are you sure?',
btnCancelLabel: 'Cancel',
href: 'javascript:void(0)',
onConfirm: function(thisobj, element) {
$.ajax({
url: '../Category',
context: thisobj,
data: {
"category_id": id,
"status": value3,
"mode": button_id
},
dataType: "html",
contentType: "application/json",
type: 'GET',
success: function() {
if (button_value === "Deactivate") {
swal({
title: "Deactivated!",
text: "De-activated the course category successfully.",
type: "success"
},
function() {
});
element.closest('td').prev('td').text('Inactive');
element.prop("title", "Activate");
element.attr('value', 'Activate');
} else {
swal({
title: "Activated!",
text: "Activated the course category successfully.",
type: "success"
},
function() {
});
element.closest('td').prev('td').text('Active');
element.prop("title", "Deactivate");
element.attr('value', 'Deactivate');
}
alert(value3);
element.find('i').toggleClass('fa fa-times fa fa-check');
},
error: function() {
swal("Error", "System Error: Could not " + value2 + " the category in the database. Please try again or report to the system admin.", "error");
}
});
}
}).confirmation('toggle');
},
error: function() {
swal("Sorry!", "Cannot de-activate the category since it has active course(s) or assessment(s).", "error");
}
});
}