0

I was trying to create an autocomplete field using jquery and ajax. I tried the code below but it gives me an error that the action of the controller is not available. Here is the code in my exeternal .js file:

$(function () {
  $("#inputfield").autocomplete({
    source: '<g:createLink controller="fruit" action="findFruit">'
  });
});

And this is the code from my Fruit controller:

def findFruit = {
  def fruitsearch= Fruit.withCriteria {
    ilike 'fruit', params.term + '%'
  }

  render (fruitsearch?.'fruit' as JSON)
}

I used firebug to see whats going on, and when I tried an input on the texfield, it says that the action findFruit is not available.

Am I missing something? Or is their something wrong on the code? Thanks

Danil Speransky
  • 29,891
  • 5
  • 68
  • 79
user1577161
  • 165
  • 1
  • 4
  • 18

1 Answers1

0

Since your js code is evaluated from an external js file you should try using pure js code instead of grails tags (coz they won't work)

Try using relative path like:

$( "#inputfield" ).autocomplete({
    source: '/app-name/controller/action'
});

see if this works.

Vishal
  • 1,236
  • 1
  • 9
  • 16