使用 Ajax 自动完成

发布于 2024-09-14 00:22:34 字数 189 浏览 3 评论 0原文

我想为我的网络应用程序中的文本提供自动完成选项。我有 SQL Server 数据库表中的主数据。我在谷歌上搜索并找到了如何使用自动完成。所有示例都使用 Web 服务来执行此操作。我无法创建网络服务来实现这一点。是否可以通过在代码后面查找数据库中的值来实现自动完成?如果是这样,有人可以提供任何示例链接以供参考吗?

预先感谢,

杰卜力

I want to provide an autocomplete option for a text in my web applciation . I have the master data in the SQL server database table. I beowsed in google and found how to use autocomplte. all the examples use web service to do this. I cannot create a web service to impltement this. Is it possible to implement autocomplete by looking up values from database in code behind ? If so any one can provide any sample links for reference ?

Thanks in advance,

Jebli

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

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

发布评论

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

评论(2

刘备忘录 2024-09-21 00:22:34

这取决于数据量。有 2 个选项:

  • 在页面源中预先将其发送到客户端(可能作为 json 或 html),
  • 让客户端根据其输入查询它

如果数据量很大,则第二个选项很常见,您可以当(例如)他们输入了 3 个字符时进行查询;对于姓名和其他长列表非常有用。

重新网络服务;这不一定是完整/复杂的网络服务;只是一个返回过滤数据的简单路由或 ashx(例如)。

jquery 自动完成插件 支持这两种情况,尽管它现在已被 jquery ui 插件部分废弃。

是否可以通过在后台代码中查找数据库中的值来实现自动完成

,那么,这是在服务器上 - 所以你本质上是在谈论你说不能的相同的“网络服务”做...我还认为你应该将这两个功能(创建页面与提供自动完成结果)分离到单独的文件(/pages/whatever)中。

It depends on the volume of data. There are 2 options:

  • send it to the client pre-emptively (perhaps as json or html) in the page source
  • let the client query it based on their input

The second is common if the data-volume is non-trivial, as you can query when (for example) they've entered 3 characters; very useful for names and other long lists.

Re the web-service; this doesn't have to be a full/complex web-service; just a simple route or ashx (for example) that returns the filtered data.

The jquery autocomplete plugin supports both scenarios, although this is now partly obsoleted by jquery ui plugin.

Is it possible to implement autocomplete by looking up values from database in code behind

Well, that is at the server - so you're essentially talking about the same "web service" that you say you can't do... I also think you should separate out the 2 functions (create page vs provide auto-complete results) into separate files (/pages/whatever).

梦纸 2024-09-21 00:22:34

一种简单的方法是创建一个新的 aspx 页面,将自动完成查询作为查询字符串参数,在数据库中查找结果并以 XML 或 JSON 形式返回响应。

A simple way would be to make a new aspx page that takes the autocomplete query as querystring parameters, looks up the result in a database and returns the response as XML og JSON.

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