Bootstrap Slim Js Conflict with AJAX

Question

I have been using Bootstrap v4.1.3 where I enqueued slim js as

wp_enqueue_script('jQuerySlimJS', get_template_directory_uri().'/assets/js/jquery-3.3.1.slim.min.js');

I have written a script in the footer to save a data with ajax clicking on an ID. But I am getting an error like Uncaught TypeError: $.ajax is not a function

<script>
    jQuery.noConflict();
    (function ($){
        var ajaxUrl = '<?php echo admin_url('admin-ajax.php');?>';
        $(document).on("change","#locationsHeader",function(){
            var city = $(this).val();
            saveLocAjax(city);
        });

        $(document).on("click",".location-list li",function (e){
            e.preventDefault();
            var city = $(this).attr('data-loc');
            saveLocAjax(city);
        });

        function saveLocAjax(city) {
            var ajaxData = {
                action : 'savingLocationToSession',
                'city' : city
            }

            $.ajax({
                url : ajaxUrl,
                method : "POST",
                data : ajaxData,
                success : function (data) {
                    location.reload();
                },
            });
        }

    })(jQuery);
</script>
0
Fahad 3 months 0 Answers 7 views 0

Leave an answer