oc-shopaholic / oc-shopaholic-js-helpers

8 stars 7 forks source link

$.request is not a function #18

Open gorny-dev opened 5 years ago

gorny-dev commented 5 years ago

I want to use your package (@lovata/shopaholic-cart/shopaholic-cart-add)

I got a problem with with AJAX request inside file 'dist/app.js' (created by webpack).

app.js file:
import 'popper.js';
import 'bootstrap';

$(function () {
$.request('Cart::onAdd', {
'update': {'cart-items': '.cart-item-wrapper'}
});
});

that throws an error:

jQuery.Deferred exception: $.request is not a function TypeError: $.request is not a function
at HTMLDocument. (http://localhost/dental/combine/b71d14df8c4d4ddba2c49a7f4750930f-1567079039.js:1232:5)
at mightThrow (http://localhost/dental/combine/b71d14df8c4d4ddba2c49a7f4750930f-1567079039.js:9406:29)
at process (http://localhost/dental/combine/b71d14df8c4d4ddba2c49a7f4750930f-1567079039.js:9474:12) undefined

when i put this in html file (layout.htm)

    <script type="text/javascript" src="{{ [
        '@jquery',
        '@framework',
        '@framework.extras',
        'assets/dist/js/app.js',
        ]|theme }}.js">
    </script>
    {% scripts %}
    <script>
        $(function () {
            $.request('Cart::onAdd', {
                'update': {'cart-items': '.cart-item-wrapper'}
            });
        });
    </script>

it works correct

{% put script %} also works correct

The problem is with the file generated by webpack Jquery in webpack is fine

How to use that $.request with your package?

Ive already asked about that at octobercms : https://github.com/octobercms/october/issues/4582