2

I have a sql queries being executed via an ajax call, but I need to be able to check the progress of it and update a progress bar.

Here's my simple ajax call (using JQuery):

var strResult = (($.ajax({url: URL,async: true}).responseText));

Any ideas how I listen for changes to update the bar?

PS. This question is nothing to do with SQL.

ojsglobal
  • 525
  • 1
  • 6
  • 31

1 Answers1

-1

If you can break up the query into many components which can be executed separately, you can keep asking the server what is the progress.

For example, if you have to insert a lot of data into the db, instead of making one giant request to the db:

INSERT INTO table VALUES (..), (..), .. ;

you can break it into many insert statements:

INSERT INTO table VALUES (..);
...
INSERT INTO table VALUES (..);

Then at any stage you can always count the number of rows which can give you the percentage.

For example, you know that you are suppose to insert 20000 rows. Then using an ajax call to the server which will do this:

SELECT COUNT(*) FROM table

which will return a number up to 20000 you can calculate the percentage.

Another solution is to use websockets but this will require a lot of config.

miki725
  • 27,207
  • 17
  • 105
  • 121
  • 1
    Again, this isn't really the question. The question is nothing to do with SQL. I want to know how I can listen to the ajax call which is async? Do I add some sort of Eventlistener to it? – ojsglobal Jan 31 '12 at 16:33
  • 1
    what do you mean by listen. ajax requests are simple. Step 1. You make a request. Step 2. Server processes it. Step 3. Server returns the answer. While you are at step 2 you can't communicate with the server unless you are using web sockets. The only way them is to have two ajax requests going on at the same time. First to request the action you want. And second to poll the progress of the first one. – miki725 Jan 31 '12 at 16:37