是否有可能要更改的jQuery的自动完成jQueryUI的生成网址是什么? [英] Is it possible to change the Url which JQuery's JQueryUI Autocomplete generates?
问题描述
我使用jQuery jQueryUI的的自动完成code。它关系到我的网址我提供了(找到答案),但是追加项=<搜索查询方式>
在URL后
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 /&LT;长期/搜索查询&GT;
如。
/myurl/abcd
/myurl/hello+world
等等......
etc...
是有可能做到这一点?
否则,很可能重命名查询参数词
别的东西,..像查询
到①
,等?
Otherwise, it is possible to rename the query parameter term
to something else, .. like query
to q
, etc?
推荐答案
您可以使用 $。的getJSON ()
自己在 源
选项,例如:
You can use $.getJSON()
yourself in the source
option, for example:
$(".autocomplete").autocomplete({
source: function(req, resp) {
$.getJSON("/myurl/" + encodeURIComponent(req.term), resp);
}
});
类似的情况时,你给它一个字符串,它发送传递给方法的对象...其中有一个属性的第一个参数词
,通过做手工你刚刚更好地控制你的参数。我还使用<一个href=\"https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference%3aGlobal_Functions%3aen$c$cURIComponent\"><$c$c>en$c$cURIComponent()$c$c>上述直接生成当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的生成网址是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!