I'm using magento 1.9 version.
I am creating custom module, which contains some javascript functions to be included.
I defined all javascript functions in seperate js file and included that js in my xml file under app\design\mytheme\default.
Called the js function in my phtml file. It shows the error : (index):403 Uncaught ReferenceError: myFunction is not defined. How to solve this.
-
can you attach XML and JS files here?Neklo.com– Neklo.com2016年07月06日 09:10:47 +00:00Commented Jul 6, 2016 at 9:10
-
Sorry i cannot attch my whole XML and JS files due to my company principles.Saravanan DS– Saravanan DS2016年07月06日 09:26:00 +00:00Commented Jul 6, 2016 at 9:26
1 Answer 1
there can be several reasons of this issue:
1) Js file is not added to page (if something wrong in your XML)
2) Js file not added in Merged js file (so you can clean JS/Css cache at the bottom of Admin - System - Cache Management page)
3) Js file added, but it's code structure broken.
4) Js file added at the bottom of page, but function called before file insertion
-
Thanks for your reply @Neklo. The step 4 is caused my case. Because i called the function On document ready function. But i included the js as normal like
<action method="addJs"><script>mymodule/mymodule.js</script></action>.Saravanan DS– Saravanan DS2016年07月06日 09:23:10 +00:00Commented Jul 6, 2016 at 9:23 -
-
Is there any way to solve this.Saravanan DS– Saravanan DS2016年07月06日 09:28:24 +00:00Commented Jul 6, 2016 at 9:28
-
if <action method="addJs"> code added to <reference name="head"> section - you need to clean JS/Css cache at the bottom of Admin - System - Cache Management pageNeklo.com– Neklo.com2016年07月06日 09:29:54 +00:00Commented Jul 6, 2016 at 9:29
-
and try to call your function like Event.observe(window, 'load', function() { myFunction(); });Neklo.com– Neklo.com2016年07月06日 09:30:53 +00:00Commented Jul 6, 2016 at 9:30