Honatas / bootstrap-4-autocomplete

A simple autocomplete/typeahead for Bootstrap 4 and jQuery
MIT License
56 stars 31 forks source link

External source data #23

Open VladimirVecera opened 3 years ago

VladimirVecera commented 3 years ago

How can I get data written in autocomplete and make source data from an external file?

$('#myAutocomplete').on('input keyup', function() {
    var query = $(this).val();
    if (query.length > 2)
    {
        $.ajax({
            url:"/search.php",
            data: query,            
            dataType:"json",
            cache: false,
            processData:false,
            type:"POST",
            success: function (data) {
                $('#myAutocomplete').autocomplete({
                    source: data,
                    maximumItems: 10,
                    treshold: 2      
                });
               }
        });
    }   

});
Honatas commented 3 years ago

Hi @VladimirVecera! I didn't understand your question ... isn't this code working as expected? Have in mind that /search.php must return a JSON object in the body for it to work properly.

HenryKim2022 commented 1 year ago

He mean the 'src'...

<script>
    $('#search').autocomplete({
        source: src,
        onSelectItem: onSelectItem,
        highlightClass: 'text-danger',
        treshold: 2,
    });
</script>