`$.getJSON "#{basepath}/search/#{query}?format=json&amp;callback=?", callback`

You don't need to set up an anonymous function here. Just pass the callback.