首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >使用ajax修改后继续执行ajax请求:beforeSend

使用ajax修改后继续执行ajax请求:beforeSend
EN

Stack Overflow用户
提问于 2014-12-26 19:32:41
回答 1查看 245关注 0票数 2

在我的rails应用程序中使用jquery_ujs处理ajax表单。我修改了一个表单,通过调用ajax:beforeSend事件来发送remote: true。如果在我使用sweetalert时确认了动作的执行,我想让它继续执行

代码语言:javascript
运行
复制
$('.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

EN

回答 1

Stack Overflow用户

发布于 2015-03-08 00:39:05

你应该喜欢这个

代码语言:javascript
运行
复制
$("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将继续处理请求。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/27656545

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档