Sending Additional Info with a Typeahead Query

303 views Asked by At

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?

0

There are 0 answers