Reputation: 61
I have a Javascript file located at assets/javascripts/js/line.js
.
I am trying reference the file from one of my GSP files, but I am not able.
In the GSP file I have this tag: <asset:javascript src="/js/line.js" />
The file at this path is not being fetched when the GSP file is rendered.
What is the correct way to reference this Javascript file from the GSP file?
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>jQuery UI Tabs - Default functionality</title>
<asset:javascript src="jquery-2.2.0.min.js"></asset:javascript>
<script>
$( function() {
$( "#tabs" ).tabs();
$("#tabs").css("display","block");
} );
</script>
</head>
<body>
<div id="tabs">
<ul>
<li><a href="#tabs-1">Tab 1</a></li>
<li><a href="#tabs-2">Tab 2</a></li>
<li><a href="#tabs-3">Tab 3</a></li>
</ul>
<div id="tabs-1">
<p>Tab 1 Content</p>
</div>
<div id="tabs-2">
<p>Tab - 2 Content</p>
</div>
<div id="tabs-3">
<p>Tab - 3 Content</p>
</div>
</div>
</body>
</html>
Upvotes: 0
Views: 1353
Reputation: 413
Firstly place your javacsript files to this directory
your_project\grails-app\assets\javascripts\
Then add this line to your GSP
<asset:javascript src="jquery-1.4.2.min.js">
As you are using Grails 3.2.8
then you should use jquery-2.2.0.min.js then it will work as well
Upvotes: 0
Reputation: 1442
Try this if you want to add specific js
<script src="../assets/js/line.js"></script>
The better way is to add
<asset:javascript src="application.js"/>
in the \layouts\main.gsp file. Then add
//= require jquery-1.4.2.min
in application.js file.
Note: Make sure application.js and jquery-1.4.2.min.js are stored in the assets\javascripts folder
Upvotes: 1