I am trying to use a user source (remote) with typeahead.js and am a little worried about how to work correctly. If I hardcode the data, everything works fine, but when I try to implement a call to a remote service, that call is never called and thus never retrieves data to fill typeahead.
Here is the code:
var places = function(query, cb){
$.getJSON({
url: "https://api.foursquare.com/v2/venues/search?v=20120321&intent=global&query=%QUERY&client_id="+App.fs.client_id+"&client_secret="+App.fs.client_secret,
success: function(results){
cb(results.response.venues);
},
error: function(){
console.log("error");
}
});
};
$("#search").typeahead({
highlight: true
},
{
name: "Places",
displayKey: "name",
source: places
}
);
If I create an object with a name resultsand manually structure the data and pass it to cb, everything will work fine. However, this implementation is $.getJSONnever called. What am I missing?
Thank!
source
share