使用jquery_ujs处理我的rails应用程序中的ajax表单。我改变了一个要用remote发送的表单:true,通过callig aaax:beforeSend事件就可以了。如果我使用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。
答案 0 :(得分:0)
你应该喜欢这个
$("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确认不同,脚本执行在等待用户输入时不会停止,因此如果beforeSend中的函数没有返回false,则ajax继续继续请求。