开发者

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

开发者 https://www.devze.com 2023-03-03 19:23 出处:网络
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time,or an extraordinarily narrow situation that is not generally applic
This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center. Closed 9 years ago.

I'm t开发者_C百科rying 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?


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

0

精彩评论

暂无评论...
验证码 换一张
取 消