Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

djay's avatar
Level 2

jquery-confirm

Hi

I am using jquery confirm https://craftpip.github.io/jquery-confirm/

I am getting Uncaught TypeError: $.confirm is not a function - when I directly put the below code -

$.confirm({
                            title: 'Congratulations!',
                            content: result.message,
                            type: 'green',
                            buttons: {
                                omg: {
                                    text: 'Thank you!',
                                    btnClass: 'btn-green',
                                },
                                close: function () {
                                }
                            }
                        });``

in success:function()

here is my whole code:

jQuery(document).ready(function(){
            jQuery('#ajaxLike').click(function(e){
                e.preventDefault();
                $.ajaxSetup({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                    }
                });
                jQuery.ajax({

                    beforeSend: function(){
                        if(confirm("Are you sure you want to submit the value ?"))
                            return true;
                        else
                            return false;

                    },
                    url: "{{ url('/users/like') }}",
                    method: 'post',
                    data: {
                        userid: jQuery('#userId').val()
                    },
                    /*success: function(result){
                        console.log(result);
                    }});*/
                    success: function(result){
                       
                        jQuery('#likeCount').text(result.kbc);
                      
                        jQuery('#ajaxLike').replaceWith('<button class="btn btn-info" id="ajaxLike" disabled="disabled"><i class="fa fa-thumbs-up" style="font-size:16px"></i> You Liked</button>');

                        $.confirm({
                            title: 'Congratulations!',
                            content: result.message,
                            type: 'green',
                            buttons: {
                                omg: {
                                    text: 'Thank you!',
                                    btnClass: 'btn-green',
                                },
                                close: function () {
                                }
                            }
                        });

                    }
                });
            });
        });


I think I am putting the $.confirm code wrong way, it should be put inside something to work.

I am not well versed in jquery and all these.

Otherwise my code is working fine submitting the request with ajax.

Can someone suggest me please what I am doing wrong

Thanks in advance

0 likes
4 replies
Cronix's avatar

How did you install the library? Are you loading it with your js after jquery itself is loaded?

Load jquery first, load the confirm library that uses jquery 2nd:

<script src="/url-to-load/jquery.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.0/jquery-confirm.min.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.0/jquery-confirm.min.js"></script>
djay's avatar
Level 2

Ya I have loaded through cdn after JQuery

Thanks for reply @Cronix

Cronix's avatar
Cronix
Best Answer
Level 67

I don't know how you have everything set up, but you are using jQueryeverywhere else instead of $, so perhaps this

$.confirm({

should be

jQuery.confirm({

Also force-refresh your browser in between changes to ensure the newest code is loaded unless you are using laravel mix and version()

djay's avatar
Level 2

@Cronix

Thanks

Anyhow it got solved. To promote the culture of helping each other I am ticking your answer as correct

Thanks

Please or to participate in this conversation.