0

This is my script from my phtml file:

<script type="text/x-magento-init">
    {
        "*": {
            "Vendor_Namespace/js/custom": {
                "ajaxShipmentUrl": "<?php echo $block->getUrl('vendor_namespace/ajax/scanShipment'); ?>"
            }
        }
    }
</script>

I want to get the value of my ajaxShipmentUrl paramater in the custom js file. This is the content of the custom js file:

define([ 'jquery', 'jquery/ui'],
    function ($) {
        'use strict';
        $.widget('mage.fulfillment', {
            options: {
                // Define variables
            },
            _init: function (config) {
                console.log(config);
                // ... the rest of the script
            },
     // ... the rest of the script

     return $.mage.fulfillment;
});

Is there a way to get the ajaxShipmentUrl in my _init method ?

Thank you

1 Answer 1

7

You can get the values passed from phtml to widget in any function using below code,

this.options.ajaxShipmentUrl

2
  • Woaw, so fast, thnx , it works. I learnt smth today :) Commented Feb 24, 2020 at 12:27
  • Cheers bro ....
    – aravind
    Commented Feb 24, 2020 at 12:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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