Bootstrap 3 typeahead.js - remote url attributes

后端 未结 3 504
孤街浪徒
孤街浪徒 2020-12-10 18:17

I\'m trying to call my remote url with added attributes to the url.

For now I have this working:

$(\'#league\').typeahead({
        remote: \'/typeah         


        
3条回答
  •  孤街浪徒
    2020-12-10 18:49

    Here is a complete example with the QUERY result as well passed. Note that when the remote method is used variable substitution no longer functions. Thanks to hieu-nguyen for the majority of it!

    jQuery('#city').typeahead({
        name: "cities",
        remote: {
            url: current_web_root + '?action=ajax|getcities&query=%QUERY',
            replace: function () {
                var q = current_web_root + '?action=ajax|getcities&query=' + jQuery('#city').val();
                if (jQuery('#state').val()) {
                    q += "&state=" + encodeURIComponent(jQuery('#state').val());
                }
                return q;
            }
        },      
        cache: false
    }); 
    
    jQuery("#state").change(function (e) {
        jQuery('#city').val("");
    });
    

提交回复
热议问题