JQuery 自动完成服务器端匹配 [英] JQuery autocomplete server-side matching

查看:18
本文介绍了JQuery 自动完成服务器端匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置自动完成字段.

I am trying to setup an autocomplete field.

我已经阅读了 JQuery UI 文档,但所有示例都假设源是一个静态项目列表,JQuery 将从这些项目中选择匹配的条目(我的意思是静态 = 列表是完整的,不依赖于用户输入).

I'v read the JQuery UI documentation, but all the example assume the source is a static list of items from which JQuery will pick matching entries (I mean static = the list is complete and doesn't depend on what the user typed).

这是远程数据源"示例中的代码:

Here is the code from the "remote datasource" example:

$( "#birds" ).autocomplete({
    source: "search.php",
    ...

我希望 JQuery 调用 search.php?query=mytext(此 URL 返回匹配项列表),因为我需要使用 PHP 在数据库中查找建议.

I would like JQuery to call search.php?query=mytext (this URL returning a list of matching items) because I need to lookup suggestions in a database using PHP.

有没有办法做到这一点?可能我没看懂文档?

Is there a way to do that? Maybe I didn't understand the documentation?

推荐答案

来自关于自动完成的 jQuery UI 文档:

from the jQuery UI Documentation on autocomplete:

只需指定源选项,就可以自定义自动完成以处理各种数据源.数据源可以是:

Autocomplete can be customized to work with various data sources, by just specifying the source option. A data source can be:

  • 一个包含本地数据的数组
  • 一个字符串,指定一个 URL
  • 回调

再往下

当使用字符串时,自动完成插件期望该字符串指向将返回 JSON 数据的 URL 资源.它可以在同一台主机上,也可以在不同的主机上(必须提供 JSONP).请求参数term"被添加到该 URL 中.数据本身可以采用与上述本地数据相同的格式.

When a String is used, the Autocomplete plugin expects that string to point to a URL resource that will return JSON data. It can be on the same host or on a different one (must provide JSONP). The request parameter "term" gets added to that URL. The data itself can be in the same format as the local data described above.

您是否尝试过您提供的代码?它应该调用 url search.php?term=mytext

have you tried the code you give? it should call the url search.php?term=mytext

这篇关于JQuery 自动完成服务器端匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆