Ajax在这两种情况下运行
问题描述:
我确认了提交值并获得成功提醒后,我创建了一个输入框,但我也取消了取消按钮的成功?Ajax在这两种情况下运行
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 !");
});
答
当使用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!");
});
});
});
+0
谢谢工作现在。 –
什么是'inputValue'可变的,当您单击取消的价值? –
inputValue用于输入值字段,一个文本框。 –
是的,我们知道变量的实际值是多少?你正在做一个如果在该变量,以决定是否需要做阿贾克斯调用 –