Добавить sweetalert в вывод функции

Есть функция

<script type="text/javaScript">
        function myDream()
        {
        jQuery.ajax({            
            type   : 'post',
        url    : '?option=com_ajax&module=hello_ajax_world&format=raw',
            success: function( response ) {
                if (response.length > 1) {
                alert(response);
        }else{
        window.location.href = 'mydream';
        }
            }
        });
     }
        </script>

которая выводит сообщение в браузере - сообщение появляется при нажатии на кнопку по ссылке: javascript:myDream(); Сама функция описана так:

$js = <<<JS
(function ($) {
    $(document).on('click', 'input[type=submit]', function () {
        var value   = $('input[name=data]').val(),
            request = {
                    'option' : 'com_ajax',
                    'module' : 'hello_ajax_world',
                    'data'   : value,
                    'format' : 'raw'
                };
        $.ajax({
            type   : 'POST',
            data   : request,
            success: function (response) {
                $('.status').html(response);
            }
        });
        return false;
    });
})(jQuery)
JS;

Куда добавить вывод sweetalert плагина, чтобы сообщение появлялось не обычным alert, а с помощью sweetalert?


Ответы (1 шт):

Автор решения: Vadim

Создаёшь функцию myalert и вызываешь как обычный alert

// в самом начале своего js файла
const aswal=(atitle=false, atext=false)=>{
    return Swal.fire({
        icon: 'error',
        title: atitle || 'empty',
        text: atext || 'sample text',
    });
};

// в ажахсе
let response = 'super puper alert';
aswal('my amazing', response);
  • Q: Куда добавить последнюю строку?
  • A: Вместо alert(response);
→ Ссылка