我正在使用bootbox登录我的用户,如果有错误,我想让它保持打开状态。从this link看起来,我所要做的就是使用return false。但是,我的bootbox仍在关闭;我猜测这是因为我发送了一个ajax请求来执行表单验证。
当我检查用户名/密码在服务器端是否有效时,有没有办法使引导盒保持打开状态?而且,一种似乎有效的解决方案是创建一个函数来打开bootobx,并在失败时重新打开它,但更“干净”的解决方案会更受欢迎。
bootbox.dialog({
message: message,
title: "Log In",
buttons: {
success: {
label: "Submit",
className: "btn-success",
callback: function() {
var username = $('.bootbox-body input[name="username"]').val();
var password = $('.bootbox-body input[name="password"]').val();
$.post('ajax/sign_in.php', {
username: username,
password: password
}, function() {}, 'json').done(function(o) {
if (o.success) {
//send them to a new page
}
if (o.error) {
$('#login_error').html(o.error);
//oops! the bootbox has closed
}
});
}
}
}
});发布于 2016-02-11 02:21:49
一种选择是在进行ajax调用后使引导盒回调返回false (以防止它自动关闭),然后在登录成功时使用引导模式的hide方法(link)手动隐藏它。所以就像这样:
var box = bootbox.dialog({
title: title,
message: message,
buttons: {
success: {
label: "Submit",
className: "btn-success",
callback: function() {
var username = $('.bootbox-body input[name="username"]').val();
var password = $('.bootbox-body input[name="password"]').val();
$.post('ajax/sign_in.php', {
username: username,
password: password
}, function () { }, 'json').done(function (o) {
if (o.success) {
box.modal('hide');
}
if (o.error) {
$('#login_error').html(o.error);
}
});
return false;
}
}
}
});https://stackoverflow.com/questions/35293963
复制相似问题