是否可以更改 JQuery 的 JQueryUI 自动完成生成的 Url? [英] Is it possible to change the Url which JQuery's JQueryUI Autocomplete generates?
问题描述
我正在使用 JQuery JQueryUI 的自动完成代码.它转到我提供的 url(以查找答案),但在 url 后附加 ?term=
.
I'm using JQuery JQueryUI's AutoComplete code. It goes to my url i provide (to find the answers), but appends ?term=<search query>
after the url.
我正在尝试获取以下网址 ...
I'm trying to get the following url intead ...
/myurl/<术语/搜索查询>
例如.
/myurl/abcd
/myurl/hello+world
等等...
可以这样做吗?
否则,可以将查询参数 term
重命名为其他名称,例如将 query
重命名为 q
等?>
Otherwise, it is possible to rename the query parameter term
to something else, .. like query
to q
, etc?
推荐答案
您可以使用 $.getJSON()
自己在 source
选项,例如:
You can use $.getJSON()
yourself in the source
option, for example:
$(".autocomplete").autocomplete({
source: function(req, resp) {
$.getJSON("/myurl/" + encodeURIComponent(req.term), resp);
}
});
发生了类似的事情 当你给它一个字符串时,它会发送第一个作为对象传递给方法的参数......它有一个属性term
,通过手动执行,你只是对你的参数有更多的控制.我也在使用 encodeURIComponent()
直接生成 url 时,上面是安全的(例如空格到 +
等).
Something similar happens when you give it a string, it sends the first parameter passed to the method as the object...which has a property term
, by doing it manually you're just getting more control over your parameters. I'm also using encodeURIComponent()
above to be safe when generating a url directly (e.g. spaces to +
, etc.).
这篇关于是否可以更改 JQuery 的 JQueryUI 自动完成生成的 Url?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!