It seems cannot use jquery lib inside the x-magento-init type javascript. How to call a ajax function in x-magento-init type javascript? Thanks


As far as I know, we can call a ajax function in x-magento-init:


<script type="text/x-magento-init">
            "[data-role=tocart-form], .form.map.checkout": {
                "catalogAddToCart": {}

And then, navigate to

ajaxSubmit: function(form) {
            url: form.attr('action'),
            data: form.serialize(),
            type: 'post',
            dataType: 'json',
            beforeSend: function() {
                if (self.isLoaderEnabled()) {
            success: function(res) {

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.