0
<script type="text/javascript">
                require(['jquery'],function($){
                $(document).ready(function(){
                   alert('ok');
                });
            });
//$("#popup-modal<?= $currentproduct_id; ?>").closeModal();</script>

I want to add this script in controller execute function but getting error

Uncaught ReferenceError: require is not defined

Please do guide me something where am i wrong

  • share controller execute method's code – kunj Feb 15 at 8:58
  • i have written above script in execute function – Arjun Feb 15 at 9:02
  • have you added something to return your script for render? – kunj Feb 15 at 9:04
3

If your execute() method in the controller outputs whatever code directly, there is no layout rendered and also there are no javascript libraries loaded.

It's better to create a to create a layout xml file for your controller and a phtml template and include the javascript code there. That will work unless you remove in your layout xml the blocks which are loading the javascript libraries.

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.