When I call my RestFull API, I can return fair results fast and good results take some time. They will be wrapped in different JSON structure. Is this doable with AJAX in one call and how would the client side look like?
Asked
Active
Viewed 51 times
1 Answers
0
When you make an request, you get a single response.
For whatever reason (slow server, slow connection speed, etc.), the response could take a while to arrive but your browser will still wait for it.
Also see Browser Timeouts
-
My question was certainly not clear. On the server side I make two SQL queries concurrently. The first one responds fast and I would like to transmit the first results to the client. The second reply takes longer. I wonder if an AJAX call is the right technology for that and can I send two JSON-objects over the line? Will the first one sent when I write to the stream on the server side? – JohnDoe Mar 20 '16 at 18:39
-
@JohnDoe No worries - I did wonder, but I think my answer will still suffice. Once the browser has received a response from an async (i.e. AJAX) request, the connection is closed. You can't keep it open to return further data. You might want to look into [websockets](https://developer.mozilla.org/en-US/docs/Web/API/WebSockets_API) as an option. – Phil Pill Mar 20 '16 at 19:03