Javascript 返回AJAX响应后防止默认操作
在AJAX调用GetCurrentTime并返回response对象之后,调用的新sweet警报只停留一秒钟,因为prevent default不会停止事件的运行。如何停止执行此操作,使弹出窗口在单击之前保持不变。初始事件.preventDefault()的工作方式与单击按钮时相同Javascript 返回AJAX响应后防止默认操作,javascript,jquery,asp.net,ajax,sweetalert,Javascript,Jquery,Asp.net,Ajax,Sweetalert,在AJAX调用GetCurrentTime并返回response对象之后,调用的新sweet警报只停留一秒钟,因为prevent default不会停止事件的运行。如何停止执行此操作,使弹出窗口在单击之前保持不变。初始事件.preventDefault()的工作方式与单击按钮时相同 function alertYourself(ctl, event) { var defaultAction = $(ctl).prop("href"); event.prevent
function alertYourself(ctl, event) {
var defaultAction = $(ctl).prop("href");
event.preventDefault();
swal({
title: 'SUBMIT DATA',
input: 'email',
showCancelButton: true,
confirmButtonText: 'Submit',
},
function (isConfirm) {
if (isConfirm) {
event.preventDefault();
$.ajax({
type: "POST",
url: "Home.aspx/GetCurrentTime",
data: '{name: "ITS ALIVE" }',
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (response) {
event.preventDefault();
swal({
title: "Are you sure?",
text: response.d,
type: "warning",
showCancelButton: true,
confirmButtonText: "Continue",
cancelButtonText: "Cancel",
closeOnConfirm: false,
closeOnCancel: true
},
function (isConfirm) {
if (isConfirm) {
window.location.href = defaultAction;
return true;
} else {
return false;
}
});
},
error: function (response) {
this.event.preventDefault();
}
});
} else {
}
});
}
您是否连续使用两个弹出窗口?我不知道为什么会有第二个和第三个事件。preventDefault()-一旦调用该函数,默认值就已经被阻止了。另外,在AJAX响应之后调用它是无用的,因为外部函数已经返回。我以前从未使用过这个甜蜜的提醒,但这可能是因为您已经打开了一个提醒框,并且正在尝试打开另一个提醒框。在打开新警报之前,您可能需要通过编程关闭第一个警报-在打开新警报之前,您甚至可能需要设置一个超时,例如100毫秒。