3

I am following the "Using Play Framework with scala" tutorial. I am able to follow all the steps except the last one to use the coffeescript with jquery. I can see the javascript file getting generated, but in the browser, I am seeing this error "ReferenceError: $ is not defined". I am new to javascript and coffeescript, here is my coffeescript code:

main.coffee

and here is the javascript as shown in the browser console Generated Java Script

is there some syntax issue that can cause the problem? Help appreciated. I am attaching the image, if indentation could be one of the reasons for this to fail.

Gaurav Abbi
  • 645
  • 9
  • 23
  • 2
    You do understand `$` is for the jQuery library, right? Did you include jQuery on your page? `ReferenceError: $ is not defined` says it's not – Ian Jul 20 '14 at 14:23

3 Answers3

0

add this line (depending on your version of jQuery)

<script src="@routes.Assets.at("javascripts/jquery-1.11.2.js")" type="text/javascript"></script>

to the <head> </head> section in app/views/main.scala.html .

For me, this template is loading for every page. but first you need to download jQuery and add it to your javascripts folder (under public).

inquisitive
  • 3,738
  • 6
  • 30
  • 56
0

In Play 2.3: Note the lib/jquery/jquery.js path. The lib folder denotes the extract WebJar assets, the jquery folder corresponds to the WebJar artifactId, and the jquery.js refers to the required asset at the root of the WebJar.

So just add

<script type="text/javascript" src="@routes.Assets.versioned("lib/jquery/jquery.js")"></script>

to the <head> </head> section in app/views/main.scala.html.

davidrdgz
  • 11
  • 2
-1

basic javascript, now everything seems crystal clear.

Just one line to include jquery in the index.scala.html to include jquery plugin.

Gaurav Abbi
  • 645
  • 9
  • 23