I need to call a function, that is written in block, but I need to call on every time the page loads.
Problem:
What Issue I am facing now is, I can call a function written in the block, but it was called only once, after refreshing the page or reloading, the same function was not called. Anyone has an idea, if so , please share it.
How do we achieve this via Knockout js or any other method?
To call a block function using Knockout.js in Magento 2, you need to follow these steps:
Create a Custom Block:
Expose Block Function to JavaScript:
Use Knockout.js to Bind Data:
Hey,
You can add the phtml file using the block and, in that phtml file you can do JS ajax code and, in controller you can call block method Alternate option that is in knockout js. you can add the ajax and call controller.
Thank You!