当我确认提交值并获得成功警报时,我已经创建了一个输入框,但我也在取消按钮上取得了成功?
swal({
title: " Asking price for " + askData[0] + "?",
text: "If you are sure press OK or edit this text",
type: "input",
inputType: "text",
inputValue: "Hello " + askData[1] + ", I am interested in buying your " + askData[0] + " of Variety :" + askData[3] + ". Please update the Price!",
showCancelButton: true,
closeOnConfirm: false,
showLoaderOnConfirm: true
}, function (inputValue) {
if (inputValue === "") {
swal.showInputError("Please write something !");
return false;
}
$.ajax({
url: urlEnq,
type: "GET"
});
$.ajax({
url: 'saveUserMessage',
type: "POST",
data: {
fieldUserId: fieldUserId,
filedUserCompanyId: filedUserCompanyId,
message: inputValue
},
})
.done(function (data) {
swal("Done!", "Your message has been successfully sent.", "success");
})
.error(function (data) {
swal.showInputError("Please write something !");
});
答案 0 :(得分:2)
使用SweetAlert时,如果点击取消,则传入回调函数的变量值将为false
而不是''
。
我已更新您的jsfiddle以显示此信息,请参阅以下更新代码:
$('button.delete-account').click(function (e) {
swal({
title: "Are you sure you want to delete your account?",
text: "If you are sure, type in your password:",
type: "input",
inputType: "password",
showCancelButton: true,
closeOnConfirm: false
}, function (typedPassword) {
if (typedPassword === false) {
return;
}
if (typedPassword === "") {
swal.showInputError("You need to type in your password in order to do this!");
return false;
}
$.ajax({
url: "/api/delete-account",
data: { password: typedPassword },
type: "POST"
}).done(function (data) {
swal("Deleted!", "Your account has been deleted!", "success");
}).error(function (data) {
swal.showInputError("Your password is wrong!");
});
});
});