JQuery 自动完成 1.8 中的附加搜索词
我是 Jquery 的新手,所以我可能会遗漏一些明显的东西......
我正在使用 JQuery 的 1.8 自动完成小部件进行搜索。用户输入 3 个字符后,该功能被触发。因此,下面函数中的“term”代表街道名称中的字符。
但是,用户已经输入了他们的邮政编码和门牌号,我希望这些值也传递给查询。我也如何发送这些值?我只能弄清楚如何发送单个“术语”。
(如果重要的话,我正在使用 ASP.Net MVC3)
$("#SearchStreet").autocomplete({
source: function (request, response) {
$.ajax({
url: "/VoterAndPollingPlaceLookup/PollingPlaceSearch/FindStreet",
dataType: "json",
data: {
term: request.term
},
success: function (data) {
response($.map(data, function (item) {
return {
value: item
}
}));
}
});
},
minLength: 3,
delay: 0
});
编辑:在帮助之后,下面是我的新代码,工作得很好!
我做了以下更新: 我的控制器操作被调用:
Public Function FindStreet(term As String, searchZip As String, searchHouse As String) As JsonResult
.....returns results
End Function
下面是更新的 Jquery。
$("#SearchStreet").autocomplete({
source: function (request, response) {
$.ajax({
url: "/OnlineVoterRegistration/ApplicationDetails/FindStreet",
dataType: "json",
data: { term: request.term,
searchZip: $("#SearchZip").val(),
searchHouse: $("#SearchHouse").val() }
success: function (data) {
response($.map(data, function (item) {
return {
value: item
}
}));
}
});
},
minLength: 3,
delay: 0
});
I'm a newbie with Jquery, so I may be missing something obvious... .
I am using JQuery's 1.8 autocomplete widget for a search search. After the user enters 3 characters the function is triggered. So "term" in the below function represents the characters in the street name.
However, the user will have already input their zip code and house number, and I would like those values to be passed to the query as well. How to I send those values, too? I can only figure out how to send the single "term".
(If it matters, I'm using ASP.Net MVC3)
$("#SearchStreet").autocomplete({
source: function (request, response) {
$.ajax({
url: "/VoterAndPollingPlaceLookup/PollingPlaceSearch/FindStreet",
dataType: "json",
data: {
term: request.term
},
success: function (data) {
response($.map(data, function (item) {
return {
value: item
}
}));
}
});
},
minLength: 3,
delay: 0
});
EDIT: after help, the below is my new code that works just fine!
I have made the following updates:
My controller action that is being called:
Public Function FindStreet(term As String, searchZip As String, searchHouse As String) As JsonResult
.....returns results
End Function
Below is the updated Jquery.
$("#SearchStreet").autocomplete({
source: function (request, response) {
$.ajax({
url: "/OnlineVoterRegistration/ApplicationDetails/FindStreet",
dataType: "json",
data: { term: request.term,
searchZip: $("#SearchZip").val(),
searchHouse: $("#SearchHouse").val() }
success: function (data) {
response($.map(data, function (item) {
return {
value: item
}
}));
}
});
},
minLength: 3,
delay: 0
});
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
ajax 请求的
data
参数接受 JSON 对象,因此您只需将其他属性添加到该对象即可。像这样:在控制器操作中,您必须添加参数
zipCode
和houseNumber
。The
data
parameter for the ajax request accepts a JSON object so all you have to do is add the other properties to that object. Like this:In your controller action you have to add the parameters
zipCode
andhouseNumber
.