是否可以更改 JQuery 的 JQueryUI 自动完成生成的 Url?

发布于 2024-09-18 23:34:33 字数 387 浏览 2 评论 0原文

我正在使用 JQuery JQueryUI 的自动完成代码。它转到我提供的网址(以查找答案),但在网址后面附加 ?term=

我正在尝试获取以下网址...

/myurl/ 例如

/myurl/abcd
/myurl/hello+world

等等...

可以这样做吗?

否则,可以将查询参数 term 重命名为其他名称,例如将 query 重命名为 q 等?

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/<term / search query>

eg.

/myurl/abcd
/myurl/hello+world

etc...

is it possible to do this?

Otherwise, it is possible to rename the query parameter term to something else, .. like query to q, etc?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生来就爱笑 2024-09-25 23:34:33

您可以在 $.getJSON() 中自行使用href="http://jqueryui.com/demos/autocomplete/#option-source" rel="noreferrer">选项,例如:

$(".autocomplete").autocomplete({ 
  source: function(req, resp) {
    $.getJSON("/myurl/" + encodeURIComponent(req.term), resp);
  }
});

类似的事情发生当你给它一个字符串时,它会发送作为对象传递给方法的第一个参数...它具有属性 term,通过手动执行此操作,您可以更好地控制参数。我还使用 encodeURIComponent()直接生成 url 时(例如 + 之间的空格等),请执行上述操作以确保安全。

You can use $.getJSON() yourself in the source option, for example:

$(".autocomplete").autocomplete({ 
  source: function(req, resp) {
    $.getJSON("/myurl/" + encodeURIComponent(req.term), resp);
  }
});

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.).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文