繁体   English   中英

SweetAlert不等待

[英]SweetAlert doesn't wait

我在ajax中使用swal,但是swal不要等到您提出请求后,这是我的代码:

$("#btnSubmit").click(function() {
    var data = $("#myForm").serialize();

    $.ajax({
        type: "POST",
        url: myURL,
        data: data,
        success: function(response) {
            swal({
                title: "Success",
                text: "Data added.",
                icon: "success"
            })
                .then(() => {
                    window.location.replace(referrer);
                });

        }
    });
});

我还没有运气重现您的问题。 有关示例,请参见代码段。 控制台中是否有任何错误? 这些将有助于我们看到。

 const btn = document.querySelector('#test'); btn.addEventListener('click', () => { fetchTodos() .then(() => { swal({ title: 'Success', text: "This is in fetchTodos().then()", icon: 'success', }).then(() => console.log('Do something here')); }) }); function fetchTodos() { return fetch('https://jsonplaceholder.typicode.com/todos/1') .then(response => response.json()) .then(json => console.log(json)) } 
 <script src="https://cdnjs.cloudflare.com/ajax/libs/sweetalert/2.1.2/sweetalert.min.js"></script> <button id="test"> SweetAlert </button> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM