1

I have this ajax code and i want to use alert modal of magento 2.

<script>
    require(['jquery'],function($){
        $(document).ready(function() {
            $("#vendor_search").on('click',function(){
                event.preventDefault();
                var input = $("#customer_id").val();
                var param = { data : input};
                var url = '<?php  echo $block->getUrl('kyanh/vendor/getinfo');?>';
                $.ajax({
                    url: url,
                    type: "POST",
                    data: param,
                    dataType: 'json',
                    cache: false,
                    showLoader: true
                }).done(function(data)
                {
                    var ar = [
                        data['cus_id'],
                        data['lname'],
                        data['email']
                    ];
                    alert(ar);
                });
            });
        });
    });
</script>

Pls help me, tks for reading!

0

You can try this code.

<script>
    require([
    'jquery',
    'Magento_Ui/js/modal/alert'
    ],function($,alert){
        $(document).ready(function() {
            $("#vendor_search").on('click',function(event){

                event.preventDefault();
                var input = $("#customer_id").val();
                var param = { data : input};
                var url = '<?php  echo $block->getUrl('kyanh/vendor/getinfo');?>';
                jQuery.ajax({
                    url: url,
                    showLoader: true,
                    dataType:'json',
                    data: param,
                    type: "POST",
                    success: function(result){                   
                     alert({
                            title: 'Some title',
                            content: result.msg,
                            actions: {
                                always: function(){}
                            }
                        });

                    }
                 });


            });
        });
    });   

</script>

enter image description here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.