8

I'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)
jharrvis
  • 135
  • 1
  • 1
  • 6

2 Answers2

33

try switch "icon", for "type", like this:

               Swal.fire({
                    type: 'info',
                    title: hasil.message,
                    showConfirmButton: false,
                    timer: 1500
                });

I just had the same problem and found this solution!

  • 1
    remember, use this solution only if you want to keep sweetalert2 version 8.x, like in the time of this writing cdnjs from libman could only deliver 8.x version, but unpkg delivers it at 9.x which use "icon" parameter name! – Alan Miguel Rocha Nov 25 '19 at 04:38
2

The new major version (v9) was released a couple of days ago, please update your sweetalert2 dependency:

package.json:

"sweetalert2": "^9.0.0",

Or, if you're using CDN:

<script src="https://cdn.jsdelivr.net/npm/sweetalert2@9"></script>

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

Limon Monte
  • 44,025
  • 43
  • 163
  • 189