javascript - SweetAlert:单击确定后如何发送 POST 请求?

标签 javascript html sweetalert

我想给你 - SweetAlert对于我的网站。现在我需要使用此代码配置 SweetAlert,以便在单击“确定”按钮时,它将通过 POST formaction="/link/link"post="test=1"

swal({
    title: "Are you sure?",
    text: "You will not be able to recover this imaginary file!",
    type: " warning ",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "Yes, delete it!",
    cancelButtonText: " No, cancel plx!",
    closeOnConfirm: false,
    closeOnCancel: false
}, function(isConfirm) {
    if (isConfirm) {
        swal("Deleted!", "Your imaginary file has been deleted.", "success");
    } else {
        swal("Cancelled", "Your imaginary file is safe: ) ", " error ");
    }
});

我想问你,我该如何构建它。

最佳答案

在 swal 回调中添加您的 POST 请求触发器,如下所示:

swal({
    title: "Are you sure?",
    text: "You will not be able to recover this imaginary file!",
    type: " warning ",
    showCancelButton: true,
    confirmButtonColor: "#DD6B55",
    confirmButtonText: "Yes, delete it!",
    cancelButtonText: " No, cancel plx!",
    closeOnConfirm: false,
    closeOnCancel: false
}, function(isConfirm) {
    if (isConfirm) {
        swal("Deleted!", "Your imaginary file has been deleted.", "success");
        post('/link/link', {test: '1'});  // <<< This is what I added
    } else {
        swal("Cancelled", "Your imaginary file is safe: ) ", " error ");
    }
});

The definition of the function post() is found here

关于javascript - SweetAlert:单击确定后如何发送 POST 请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27035488/

相关文章:

html - 在 Selenium IDE 中断言元素颜色

Javascript:过滤数组中的元素部分

javascript - 在 Array.prototype 中为 "for each"循环传递参数的语法是什么?

javascript - 如何让 JavaScript 中的按钮只执行一次代码?

html - 时事通讯无法隐藏 gmail 上的响应内容以及当我尝试转发电子邮件时

ruby-on-rails - rails 4 : How to get sweet alert confirm work?

javascript - 用模态替换 javascript 警报

css - 页面底部的div,下面有图片

javascript - JQuery swal 确认不提交

javascript - 甜蜜的警报。在警告框中显示倒计时