views:

26

answers:

1

guys, i have a html page where onclick of a button a ajax request is sent to server , the request calls a jsp page which runs an oracle procedure.The procedure runs the logic and places it in a temp table . once procedure is completed , the values are returned to the client by selecting values from tmp table. as the response is too late . the data is not received at the client side.

solution: i tried to run the procedure in a separate thread using a ajax call. when the procedure is completed a global flag is set to indicate that the data is generated. if the response is 500 , a second ajax call invoked by timeout function after 10000 ms . the second call checks the global flag ,if true then reads from table and sends the response. if not again a timeout is set at the client side. this solution is not mature enough. , as the procedure may take long time to respond.

please let me know a good solution for this problenm?

+1  A: 

This is the classic "Quote Comparison Website" model.

You need to make your requests more specific, like this...

First - you send the initial request for the long-running process using AJAX and you get back a "RequestId".

Second - you call a "Check Status" service with your request id and receive a status. If you get "Working" you pause for a bit and re-check. If you get "Complete" you move onto the third stage.

Third - you call the "Get Results" service with your request id and instantly get the pre-prepared result back.

You will want to add a number of attempts into the second step - so if you've waiting for 10 minutes you give up and apologise to the user.

Sohnee