0

Am calling an ajax call to validate n number of data.
Since it takes lot of time to complete, I thought of showing the user the progress bar or tell that 1/n completed
In-order to display that, I should get the status from the controller.

Can someone please tell me is there any way to get the status from controller before completing? Or Is there any other better way to implement.

Soviut
  • 88,194
  • 49
  • 192
  • 260
  • Here is interesting answer by Matthew Flaschen, May be this helps you http://stackoverflow.com/questions/3163229/check-status-of-a-jquery-ajax-request – Udit Rawat Sep 30 '16 at 05:44
  • 1
    First about which framework you are talking about. Second I advise you to post the relevant code so anyone willing to help you can see what you are doing. So be kind and post your code :) – Franco Sep 30 '16 at 05:47

2 Answers2

0

Since ordinary AJAX is a classic request-response you cannot get progress information from the server with the same connection. You have to make a new AJAX call to ask the server for the task progress. This is called a heartbeat pooling technique.

Better solution is to use some kind of persistent connection, for example Websockets. That way server can push a message with progress information to the client over the same connection that initiated the task. Websocket adoption is strong among browsers.

srigi
  • 1,682
  • 1
  • 15
  • 30
  • From the question it is clear that asker wants to know the progress of the server task, not the progress of the HTTP request. – srigi Sep 30 '16 at 07:25