How do I pass an extra variable to Jquery Autocomplete field in souce?

时间:2018-02-03 09:26:31

标签: jquery jquery-ui-autocomplete

$( "#location" ).autocomplete({
    source: 'property-location/?city=' + $('[name=city]').val() + $(this).val()
});

1 个答案:

答案 0 :(得分:0)

You can also pass function into suorce instead of api url.

$("#location").autocomplete({
    source: 'property-location/?city=' + $('[name=city]').val() + $(this).val(),
    source: function(request, response) {
        $.getJSON('property-location/', {
            term: extractLast(request.term),
            city: $('[name=city]').val()
        }, response);
    }
});