jQuery Autocomplete using extraParams to pass additional GET variables

后端 未结 13 753
独厮守ぢ
独厮守ぢ 2021-01-31 17:23

I am referring specifically to the jQuery Autocomplete v1.1 plugin by Jörn Zaefferer [source: http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/] as there seems to

13条回答
  •  春和景丽
    2021-01-31 17:45

    With regards to the most voted answer, I think there is a much simpler syntax by just appending the extra request value into the source url.

    This:

    $("#city_id").autocomplete({
        source: src+"?country_id="+$("#country_id").val().
        min_length: 3,
        delay: 300
    });
    

    does the same as:

    $("#city_id").autocomplete({
        source: function(request, response) {
            $.ajax({
                url: src,
                dataType: "json",
                data: {
                    term : request.term,
                    country_id : $("#country_id").val()
                },
                success: function(data) {
                    response(data);
                }
            });
        },
        min_length: 3,
        delay: 300
    });
    

    given that src is an url string.

提交回复
热议问题