在我的rails应用程序中使用jquery_ujs处理ajax表单。我修改了一个表单,通过调用ajax:beforeSend事件来发送remote: true。如果在我使用sweetalert时确认了动作的执行,我想让它继续执行
$('.content>.fr span:last-of-type>a').on "ajax:beforeSend", (xhr, settings) ->
swal
title: "Are you sure?"
text: "You will not be able to undo this!"
type: "warning"
showCancelButton: true
confirmButtonColor: "#DD6B55"
confirmButtonText: "Yes, delete it!"
closeOnConfirm: false
, ->
# should send the request here
swal "Deleted!", "Department has been deleted.", "success"
return
要查看它的完整版本,请访问this gist。
发布于 2015-03-08 00:39:05
你应该喜欢这个
$("body").on("click", "#element", function(e) {
swal({
title: "Are you sure?",
text: "Are you sure?",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Yes, delete it!",
closeOnConfirm: false },
function(){
// ajax goes here
}
);
});
SweetAlert与javascript confirm不同,脚本在等待用户输入时不会停止执行,因此如果beforeSend中的函数没有返回false,ajax将继续处理请求。
https://stackoverflow.com/questions/27656545
复制相似问题