jQuery Autocomplete using extraParams to pass additional GET variables

后端 未结 13 726
独厮守ぢ
独厮守ぢ 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:52

    I am using the autocomplete function that is now part of jquery ui. Passing an 'extraParams' field does not work but you can just append the values in the request query string.

    $(document).ready(function() {
        src = 'http://domain.com/index.php';
    
        // Load the cities straight from the server, passing the country as an extra param
        $("#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
        });
    });
    

提交回复
热议问题