1

Basically what I'm trying to achieve is to load data (from a database) from jQuery with an Ajax call. The Ajax call communicates to a script to load and return the data in JSON format back to jQuery. I then want to use this data for typeahead.js. I've read this thread and used the following code:

$('.subject').typeahead({
    source: function(query, process) {
        return $.get(
            '/get/subjects',
            'uni=' + query,
            function(data) {
                return process(data);
            }
        );
    }
});

The page /get/subjects returns JSON, however the typeahead proceeds to not work, with no error. However, it does alter the layout of my page, but no result!

Thanks

Community
  • 1
  • 1
Shannon Rothe
  • 1,112
  • 5
  • 15
  • 26
  • It seems to me that the link you're using as example for your code is about Bootstrap typeahead plugin, which is different from typeahead.js (at this time the former is deprecated for the latter, by the way). If you really are using typeahead.js I would recommend to you the use of Bloodhound suggestion engine, which could handle ajax calls directly, instead of the typeahead plugin. See [this](http://stackoverflow.com/questions/24523318/typeahead-js-bloodhound-remote-data-how-to-get-calling-object-reference) question, I'm asking something about ajax in there, but the code is fully working. – Fer García Jul 02 '14 at 17:24

0 Answers0