使用Jquery UI自动完成功能将额外的参数传递给源 [英] Passing extra parameters to source using Jquery UI autocomplete
问题描述
我正在尝试使用jQuery UI自动完成功能传递城市和州的额外参数.我一直在努力寻找答案,但是似乎找不到适合我的东西.
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.
我当前的代码是:
$(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);
}
});
},
});
});
自动完成功能有效,但是没有将我的城市和州参数传递给该函数.如果键入v
,它将请求URL:/autocomplete_place?term=v&test=4
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
我猜想它会根据(document).ready()
评估城市和州的val()
,并为这些表单字段获取空白值?我以为将源代码变成ajax函数可以解决该问题,但也许不会.
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.
有什么想法吗?
推荐答案
选择器中是否缺少#c4c
Are you missing a # in your selector $("#id_city").val()?
这篇关于使用Jquery UI自动完成功能将额外的参数传递给源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!