jquerygrailsgrails-plugingrails-2.5

Calling Jquery from external file in Grails


Having a jquery file inside the assets folder,and i want to call a function from it in , I used :

<script type="text/javascript" src="${assetPath(src: 'test.js')}">
<g:submitButton class="hr" name="HR Module" onclick="myFunction();"/>

but it is not working ,although if i put this function inside tags in the GSP it works perfectly .

Anything i'm missing ?


Solution

  • sample image

    Suppose in above snapshot from IDE you have to call application.js, then do it like below

    <asset:javascript src="application.js"/>
    

    Or if suppose your file is in some subdirectory under assets, then provide relative path. For example, in above snapshot say we have another application.js in scripts folder under assets dir. Then,

    <asset:javascript src="scripts/application.js"/>
    

    These are standard tags provided by assets pipeline to access resource.

    Last but not least you could similarly access css as well

    <asset:stylesheet src="bootstrap.css"/>
    

    Hope it helps!