Win a copy of Svelte and Sapper in Action this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Ajax RemoteFunction

 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have a page, and on this page I have a select box. I want that when I click on one of the choices in my select box, the selected element is send to a controller, that controller makes a GORM search, when returns it to a template which will be dynamically printed on the screen. Here is my code at the moment, actually I think the action is not even called.

Main page :


EmailController.groovy


_formSelectTemplate.gsp
 
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

actually I think the action is not even called.



Then you should do something to ensure that it is. Like breakpoints or log statements or println statements.

The only issue I see in your code is this...



Views are not prefixed with an underscore. Templates are, which is what you really need to be calling.



Technically, you should be geting a 404 from the server. I'd recommend a tool like Firebug if you're going to be trying to debug ajax / javascript stuff.
 
Jack Rackham
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes I use Firebug and I've put a println when at the beginning of the action. Look once again ;)
And I've not seen any 404 with Firebug.
 
Jack Rackham
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sorry for yesterday, I was in a hurry before leaving work, I didn't even thank you ;)

I've fixed the code with template. And anything I choose, or template or view (and renaming the gsp as it must be), it doesn't work.

And why should I get a 404 ?

EDIT : As newby in grails I ask the question, should I put the g:select into a formRemote or another form, or does it work if I let it alone ?

EDIT 2 : Here is the HTML code on the select get with Firebug :



As you see, there is no js event on the select.
 
Jack Rackham
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I fixed it. It's my fault, I've forgotten the comas, and I had to replace the double quotes by single ones.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Glad you figured it out. To answer your question about why you should have gotten a 404 (which you would have had you been hitting the controller) is because when you render a view grails goes and looks for a GSP. It would not have found one, so it would have returned a 404 to the browser.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Mac OS X IntelliJ IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
BTW, while cross-posting is a perfectly fine thing to do in order to get some answers, it would be nice if you let us know (and probably let SO know as well) that you did so.

http://stackoverflow.com/questions/7804700/grails-remoteform-ajax-doesnt-work

BeForthrightWhenCrossPostingToOtherSites
 
Jack Rackham
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Gregg Bolinger wrote:BTW, while cross-posting is a perfectly fine thing to do in order to get some answers, it would be nice if you let us know (and probably let SO know as well) that you did so.

http://stackoverflow.com/questions/7804700/grails-remoteform-ajax-doesnt-work

BeForthrightWhenCrossPostingToOtherSites



Yes that's me. I hadn't seen this (even though no one should ignore the law), I hadn't wondered about cross-posting before. So accept my apologizes if necessary.

ANd thanks for your answer about the 404 ;)
 
She'll be back. I'm just gonna wait here. With this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic