Sweetalert2: Sweetalert2 : Unknown parameter icon

Created on 7 Nov 2019  路  3Comments  路  Source: sweetalert2/sweetalert2

'm using sweealert2 on my project here's my code

header include js via jsdeliver.net

<script src="https://cdn.jsdelivr.net/npm/sweetalert2@8" charset="UTF-8"></script>
Jquery Version : jQuery v3.4.1

Script on footer

<script>
$(document).ready(function() {
    $("#updateUserProfile").submit(function(e) {
    e.preventDefault(); 

    var form = $(this);
    var url = form.attr('action');

    $.ajax({
           type: "POST",
           url: url,
           data: form.serialize(), 
           success: function(data)
           {
                $('.modal').modal('hide');
                var hasil = $.parseJSON(data);
                Swal.fire({
                    icon: 'info',
                    title: hasil.message,
                    showConfirmButton: false,
                    timer: 1500
                });
                // Swal.fire('Success', hasil.message, 'success', 1500)
                setTimeout(function(){
                    window.location.reload(1);
                }, 1500);
           }
         });
    });
});
</script>

ERROR on console.log

SweetAlert2: Unknown parameter "icon" but when i use like this no error, and icon showing up

Swal.fire('Success', hasil.message, 'success', 1500)

Most helpful comment

Older versions of SweetAlert2 had "type" and latest one has "icon" in its place.
Just check if the module you are using is latest.
It might be the case that version is old, but the code refers to latest syntax.

When you use :

Swal.fire('Success', hasil.message, 'success', 1500)

you are simply passing values in sequence, so "key" name doesn't matter here. Thus no error.

All 3 comments

Older versions of SweetAlert2 had "type" and latest one has "icon" in its place.
Just check if the module you are using is latest.
It might be the case that version is old, but the code refers to latest syntax.

When you use :

Swal.fire('Success', hasil.message, 'success', 1500)

you are simply passing values in sequence, so "key" name doesn't matter here. Thus no error.

The new major version (v9) was released a couple of days ago, please update you code:

- <script src="https://cdn.jsdelivr.net/npm/sweetalert2@8" charset="UTF-8"></script>
+ <script src="https://cdn.jsdelivr.net/npm/sweetalert2@9" charset="UTF-8"></script>

Read the release notes to see all breaking changes: https://github.com/sweetalert2/sweetalert2/releases/tag/v9.0.0

thank you for prompt answer @limonte and @naman1303

Was this page helpful?
0 / 5 - 0 ratings