首页 > 解决方案 > 无需单击任何确定或取消图标即可打开 swal

问题描述

我正在使用 sweetalert 2,我只需要打开 swal 直接调用 ajax 而不是进行确认或其他操作,我需要做什么更改,遵循此代码

https://sweetalert2.github.io/recipe-gallery/bootstrap.html

像这样尝试过

$(document).on('click','.readmore',function() {
swal({
    title: 'ajax request pending',
    text: 'processing request',
    showConfirmButton: false,
    closeOnConfirm: false,
    preConfirm => function(){
        url: 'https://example.com/controller/method/action',
        type: post,
        dataType: json,
        data: { key: value },
        success: swal.confirm( response.message ),
        error: swal.confirm( response.message )
    }
},
    function(){
        swal({
            title: 'ajax request finished',
            text: response.message,
            showSpinner: false,
            showConfirmButton: true,
            closeOnConfirm: true
    });
    }
});

但它最终出现了错误:d

Uncaught SyntaxError: missing : after property id

标签: javascriptjquery

解决方案


推荐阅读