Passing extra parameters to source using Jquery UI autocomplete [closed]

二次信任 提交于 2019-12-18 14:02:44

问题


I'm trying to pass extra parameters for city and state using the jQuery UI autocomplete function. I've been trying to find an answer to this for a while but can't seem to find something that works for me.

My current code is:

$(document).ready(function () {
    $("#id_place").autocomplete({
        source: function(request, response) {
            $.ajax({
                url: "/autocomplete_place",
                dataType: "json",
                data: {
                    term: request.term,
                    city: $("id_city").val(), 
                    state: $("id_state").val(),
                    test: 4
                },
                success: function(data) {
                    response(data);
                }
            });
        },
    });
});

The autocomplete works, but its not passing my city and state parameters to the function. If I type v it requests the URL: /autocomplete_place?term=v&test=4

I'm guessing its evaluating the val() of city and state upon (document).ready() and getting blank values for these form fields? I thought making source into an ajax function would solve that, but perhaps not.

Any ideas?


回答1:


Are you missing a # in your selector $("#id_city").val()?



来源:https://stackoverflow.com/questions/5939801/passing-extra-parameters-to-source-using-jquery-ui-autocomplete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!