SweetAlert:单击“确定”后如何发送 POST 请求?

pas*_*tuh 2 html javascript 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 ");
    }
});
Run Code Online (Sandbox Code Playgroud)

我想问你,我怎样才能建立它。

Nab*_*imi 5

在 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 ");
    }
});
Run Code Online (Sandbox Code Playgroud)

函数的定义post()可以在这里找到