How to load and display data asynchronously

I am using ASP.NET and SQL Server. I would like to load data from the database asynchronously and show data that is partially loaded immediately.

Suppose there are many records as a result of a query. After 3 seconds, it loads 20%, after which I have to process and show 20% of the data immediately, without waiting for a full response. I know $ .Ajax in jQuery to load async data. Is it possible to process a partial response, not wait for the full response and immediately show it.

Is there any way to get this?

+4
source share
7 answers

Assume in the query results tons of records

You yourself must: will the end user see the tone of the recordings right away?


You do not indicate what and how you display the data, so Iโ€™m going to assume that you display the data in a grid.

What we are doing these days in this scenario is to upload data using pages and run it when the user scrolls the grid down, you can even see this on mobile devices and even on Facebook, Twitter, etc.

It will load the first page (for example, we set the page to 20 records), so it will load the first 20 records ( page 0 ), but soon you will reach the bottom, it will automatically load another 20 records ( page 1 ).

This method is called Endless Scrolling.

+2
source

As Alex said, you cannot start showing a partial answer ... I'm sure your wait time is related to the time it takes to query and return the dataset, not the time it takes to render the date. With this, you can easily create functionality to get the first 20% of records before trying to get the last 80%. Of course, you will load each result asynchronously.

The disadvantage of this is that you need to create 2 request / response cycles and 2 database queries.

Just wondering how long it takes to run an SQL query outside of your site (for example, using SQL Manager)? How much data does 10kb or 1000kb really return? If you have a lot of text data, look at adding compression, at your answers.

+1
source

You can use a hidden IFRAME to get a response that is recorded using the ASP method response.flush (displays phased responses). Then, using the js interval, you can request this iframe body to get updated content ...

+1
source

Possible Solution:

  • You create an ASHX (Generic Handler) file or one that suits you. This file will be consulted using GET or POST.
  • Believe 2 keep procedure a. returns the number of records b. has a complete result
  • Ajax make a call to sp "a". and you will get the number of records.
  • Ajax request to sp "b", and you save part of the request in a cache or session and respond to the number of required records.
  • Ideally, the result of the consultation is in json format and may be less, but it takes longer to load in javascript. You can also return it to HTML, the transfer is harder, but much faster to load.

(I hope you understand, because my English is very bad)

0
source

No, this is not possible, you need to add several requests to process a partial response, on the server side you must partially transmit data. In the $ .Ajax (jQuery) variant, async means that synchronous requests can temporarily block the browser, disabling any actions while the request is active.

0
source

Here is a simple solution. 1. you must create a separate asp.net page that will take 1 parameter, the start record number, you must have a table with a unique record number. and get, say, 20 lines from the given start number of the record. 2. You need to call the AJAX get method, which is recursive, increasing the number of entries each time by 20 until you get the answer as NULL.

I hope he decides.

0
source

Instead of showing a partial answer, why don't you just display the data page with paging on the server side. If you have many, many records, just show only 10 records per page, returning to the database to get the next 10 when the user prints the data.

0
source

Source: https://habr.com/ru/post/1339024/


All Articles