Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to load and show data Asynchronously

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

Suppose there are tons of records in a query result. After 3 sec,It loads 20% then I have to process and show 20% data immediately, not waiting for complete response. I know $.Ajax in jQuery to load data async. Is it possible to process partial response, Not wait for complete response and show it immediately.

Is there any way to get this?

like image 411
Brij Avatar asked Feb 09 '11 13:02

Brij


2 Answers

Suppose there are tons of records in a query result

You have to aks yourself: Will the end user see a ton of records at once?


You don't specify what and how you are showing the data, so I'm going to assume that you are showing the data in something like a Grid.

What we do this days on such commun scenario is to load data using pages and fire it when the user scrolls the grid down, you can even see this in mobile devices and even on facebook, Twitter, etc...

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

This technique is called Infinite Scroll

like image 86
balexandre Avatar answered Sep 22 '22 18:09

balexandre


Like Alex said you can't start showing a partial response... I bet 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. That being said you could easily create the functionality to only get the first 20% of the records before trying to get the last 80%. Of course you would load each result asynchronously.

The downside to this is that you have to generate 2 requests/response cycles and 2 database queries.

Just curious how long does it take to run the SQL query outside of your website (using SQL Manager for example)? How much data is actually being returned 10kb or 1000kb? If you have a lot of text data, look at adding compression, to your responses.

like image 26
Aaron Barker Avatar answered Sep 23 '22 18:09

Aaron Barker