开发者

How do I properly fetch SQL data from client after pageload

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 si开发者_JS百科te, 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.


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.


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:

  • Accessing JSON Data From an ASP.NET Page Using jQuery
  • Using Ajax Web Services, Script References, and jQuery
  • Using WCF Services with jQuery and the ASP.NET Ajax Library

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

Happy Programming!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜