页面加载后如何正确从客户端获取 SQL 数据

发布于 2024-10-09 20:16:33 字数 482 浏览 4 评论 0原文

我好奇的是我有一个网站(ASP.NET),它将显示一些搜索结果。我想做的是加载带有搜索结果的页面,然后让客户端查询我的 SQL 数据库来检查并查看是否有任何搜索结果已被用户“收藏”。我对 JSON、SOAP 和 HTTP 请求了解一点,但我现在知道如何执行此操作的唯一方法是在我的项目中创建一个页面,我可以从每个返回的结果中请求该页面,并验证该页面用户从cookie中查询sql得到答案,最后向客户端返回true或false是否隐藏或显示“收藏夹”图标。

一个简单的例子(据我所知)是 Hulu 上的 Queue(_) 计数。当我加载 Hulu 网站时,它有“队列”,然后大约 1 秒后,它检索实际计数,我得到“队列(1)

”解释一下做这样的事情的正确方法?

提前致谢!

注意:任何链接将不胜感激,我一直在谷歌搜索和阅读,但还没有找到合适的资源。

What I'm curious about, is I have a site (ASP.NET), which will display some search results. What I would like to do is load the page with search results, then have the client query my SQL database to check and see if any of the search results have been "Favorited" by the user. I know a little bit about JSON, SOAP, and HTTP Requests, but the only way that I know how to do this right now would be to create a page in my project that I could request from each returned result, and have that page validate the user from the cookie, query sql for the answer, and finally return a true or false to the client on whether to hide or show the "Favorite" icon.

A simple example of this (from everything I can tell) would be the Queue(_) count on Hulu. When I load the Hulu site, it has "Queue", then about 1 second later, it retrieves the actual count, and I get "Queue(1)"

Can anyone explain the proper way to do something like this?

Thanks in advance!

Note: Any links would be greatly appreciated, I've been googling and reading, but just haven't found the right resources yet.

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

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

发布评论

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

评论(2

罪#恶を代价 2024-10-16 20:16:34

您可以通过多种方式来做到这一点。更简单的方法之一是在您所在的当前页面上使用 PageMethod,并使用调用该方法来获取结果的异步操作。

这是PageMethod 的快速概述,它使用联系表单,但您可以获得总体思路。

There are many ways that you could go about doing this. One of the more simple ways would be to use a PageMethod on the current page that you are on, and have an Async operation that calls the method to get the result(s).

Here is a quick overview of a PageMethod, it uses a contact form, but you get the general idea.

执笔绘流年 2024-10-16 20:16:34

有多种不同的方法可以从 ASP.NET 页面返回服务器进行 Ajaxy 调用。例如,在客户端,您可以使用 Microsoft 的 Ajax 库的客户端框架或不同的 JavaScript 库,例如 jQuery。在服务器端,您可以使用专门为此类请求提供服务的 ASP.NET 页面,也可以构建自己的 ASMX 或 WCF 服务。

您看过我的文章系列吗,从客户端脚本访问服务器端数据?目前分为三期:

每期都包含大量说明,并提供完整的工作示例供下载。

快乐编程!

There are quite a few different ways you can do Ajaxy calls from an ASP.NET page back to the server. For instance, on the client-side you can use Microsoft's Ajax Library's client-side framework or a different JavaScript library, like jQuery. On the server-side you can use an ASP.NET page that is dedicated to servicing such requests or you can build your own ASMX or WCF service.

Have you seen my article series, Accessing Server-Side Data from Client Script? It currently has three installments:

Each installment includes a good deal of description and walk through with a complete, working example for download.

Happy Programming!

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