1

I'm using Bootstrap 3.2.0 and jQuery 2.1.1.

I've implemented typeahead search suggestions and now wanted to go a step further. I am using the remote method and was hoping to send more than just the query to the PHP that will run a SQL script:

$(function() {

    var productEngine = new Bloodhound({
        datumTokenizer: function (datum) { return Bloodhound.tokenizers.whitespace(datum.value); },
        queryTokenizer: Bloodhound.tokenizers.whitespace,
        limit: 10,
        remote: { url: 'php/product_suggest.php?storeid='.concat(localStorage.getItem('store_id'), '&query=%QUERY') }
    });

    productEngine.initialize();

    $('input#product_suggest').typeahead(null, {
        displayKey: 'value',
        source: productEngine.ttAdapter()
    });
});

I've also tried building the URL and saving as a variable. Then attempting to call that variable in the remote.

remote: { url: builtURL } 

As I don't particularly know how this url is being parsed and used or how the %QUERY is being added, I'm assuming my issue lies in my lack of knowledge around how typeahead is processing this.

I thought this would be a fairly common request, but Google has let me down. Anyone have any suggestions or can point me towards examples of sending additional info with a typeahead query?

creimers
  • 4,975
  • 4
  • 33
  • 55
ashcanschool
  • 319
  • 3
  • 18
  • Does the remote call successfully return JSON data? Also once you return the JSON data you are going to need to convert the JSON array to a Javascript array for the Bloodhound engine to make use of it. See this answer http://stackoverflow.com/a/21533204/203371 – Ben Smith Dec 06 '14 at 23:11

0 Answers0