I am running the Magento 2 on the localhost server. http://127.0.0.1/magento3
here I've built a custom module for payment gateway.
In custom JS I want to use the mage/url.
I need to use ajax for the checkout process. Below is the code where I want to get use url.build.
But I get,
Uncaught ReferenceError: url is not defined in the console for console.log(url.build) ;
Also, I've got a function method where I want to use the ajax in Custom JS file at PATH
app\code\vendor_name\module_name\view\frontend\web\js
"IOST",
"jquery",
"mage/url"], function ($,url) {
console.log(url);
});
function transfer () {
console.log(url.build);
}
Button at this path with which i used to call the transfer() method.
app\code\vendor_name\module_name\view\frontend\web\template\payment
CODE
<span data-bind="i18n: 'Pay By IostPay'"></span>
</button>
FILE:- requirejs-config.js CODE:-
map: {
'*': {
lazyloadScript:'vendorname_modulename/js/custom_func'
}
}
};```
Does anyone know how to do it?
Thanks in advance.
transfer()
function?url
out of the define scope. check my answer.custom_func
js file