How to handle long response from server | Sololearn: Learn to code for FREE!

0

How to handle long response from server

How i can make browser to wait for the response as long as request is not send by server. For example:- user send some post request but server will take min 2 minutes to give the result but in mid of it browser will show time out or re send the request do not wait such long. How i can handle this type of request.

7/14/2020 5:19:52 PM

Rahul Roy

3 Answers

New Answer

+2

You need to configure in your backend the timeout for responses, as a recommendation try to handle this kind of request with Ajax to be able to make a loader spinner or something like that, this is good for user experience.

+2

This is for a really LONG response time process from server: When the server receives a request from a client, before start processing the long processing, server sends a response code 202 with an token id back to client. HTTP Status 202 indicates that request has been accepted for processing, but the processing has not been completed.  The client can close the connection upon receives status code 202 with an token id. Meanwhile, the server process the request, save the result with refer to token id. The client can make a new request /request/{tokenId} to check for the result at any time later.

+1

That can be an error in your code. Respectively you have to use async solution. More here: https://www.sololearn.com/learn/7893/