Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ajax/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript SweetAlert2取消按钮在ajax调用期间不可单击_Javascript_Ajax_Sweetalert2 - Fatal编程技术网

Javascript SweetAlert2取消按钮在ajax调用期间不可单击

Javascript SweetAlert2取消按钮在ajax调用期间不可单击,javascript,ajax,sweetalert2,Javascript,Ajax,Sweetalert2,我有一个在选择下拉项时调用的函数,它会触发一个弹出窗口,如: function SwalPopup(ip, method) { var methodmsg = method.charAt(0).toUpperCase() + method.slice(1); swal.fire({ text: 'Are you sure you want to '+methodmsg+' ?',

我有一个在选择下拉项时调用的函数,它会触发一个弹出窗口,如:

function SwalPopup(ip, method) {
                var methodmsg = method.charAt(0).toUpperCase() + method.slice(1);
                swal.fire({
                    text: 'Are you sure you want to '+methodmsg+' ?',
                    type: "warning",
                    showCancelButton: true,
                    confirmButtonColor: "#3085d6",
                    confirmButtonText: 'Yes, '+methodmsg+'!',
                    cancelButtonColor: '#d33',
                    showCloseButton: true,
                    showLoaderOnConfirm: true,
                    preConfirm: function () {
                        return new Promise(function (resolve, reject) {
                            var ajaxCall = $.ajax({
                                    url: 'wait.php',
                                    type: 'GET',
                                    dataType: 'json',
                                    timeout: 5000
                            })

                            ajaxCall.done(function( response ){
                                resolve(response);
                                swal.fire({
                                    type: 'success',
                                    html: 'Component with IP: <?php echo $action_ip; ?>'+ip+' was '+methodmsg+' sucessfully!',
                                    showCancelButton: false,
                                    confirmButtonColor: '#3085d6',
                                    confirmButtonText: 'Ok',
                                    allowOutsideClick: false
                                });
                            });

                            ajaxCall.fail(function( jqXhr, textStatus, errorThrown ){
                                reject(errorThrown);
                                Swal.fire('Error! It was not possible to '+methodmsg+' component with IP: <?php echo $action_ip; ?>'+ip, 'Status: '+textStatus+' Error: '+errorThrown);
                            });
                        });
                    },
                    allowOutsideClick: false
                });
            }
因此,通过Ajax调用this wait.php文件需要10秒,但我强制Ajax请求超时5秒。超时完成前,sweetalert弹出窗口显示加载动画和取消按钮。但此取消按钮不可单击。我想给它分配一个abort函数,以便在需要很长时间时取消ajax请求

这是虫子吗


感谢

这是将在下一个主要版本的SweetAlert2中更改的行为,您可以在此处跟踪进度:


现在,使用
Swal.getCancelButton().removeAttribute('disabled')
作为解决方法。

感谢您在Limon Monte的回复。我应该把变通方法放在哪里?在第一次游泳前开火?是的
sleep(10);

echo json_encode(array(
    'success' => true,
));