GrailsInAction / graina2

Source code for the 2nd edition of Grails in Action
90 stars 93 forks source link

1.6.2: Ajaxing the view displays ajaxRandom response in new page #111

Open jkwuc89 opened 9 years ago

jkwuc89 commented 9 years ago

Please note that I am working through the chapter 1 samples using Grails 2.4.3 and I am deliberately using the asset pipeline plugin in place of the resources plugin. I do not know if this makes a difference.

After entering the sample code for section 1.6.2, clicking on the Next Quote link did not update the quote. Instead, the ajax response was rendered as a separate page. Inside Chrome, I opened the developer tools and noticed that the console was displaying the following error when loading http://localhost:8080/qotd/quote/random.

GET http://localhost:8080/qotd/js/jquery/jquery-1.11.1.js 404 (Not Found)

After doing a bit of digging via Google, I discovered that adding plugin="jquery" to the following line inside random.gsp fixed this issue. The resultant line is below.

<g:javascript library="jquery" plugin="jquery"/>

pledbrook commented 9 years ago

If you're using Asset Pipeline, you shouldn't really use <g:javascript/>. Instead, either use <asset:javascript> directly or add require jquery to another Javascript asset that you use for the page.