Passing extra parameters to source using Jquery UI autocomplete [closed]
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()?
精彩评论