Is there a way to handle the status code "202 Accepted"?
Is there a way to handle the status code "202 Accepted"?
Reference: https://en.wikipedia.org/wiki/List_of_HTTP_status_codes#2xx_Success
I'm getting a 202 status back, and I would like to keep reloading the same table until the status comes back as success (200).
Is there a way to do the following:
- Keep re-sending ajax call until the status code changes
- Not reload the table each time the ajax call is sent
- Keep the "Processing..." message visible until the status has changed
Thank you for your help.
Regards,
Rob
This question has an accepted answers - jump to answer
Answers
I have no idea.
OK, now that we have that out of the way, I have questions that might point int he right direction. What else comes back from the 202 message? If the server returns 202, what key do you have to return to the server with a followup request and get the matching results?
The way the table is currently working is this:
The request is sent with the default table parameters, the data in the table is generated on a remote server. It takes some time to generate the data, so the server returns the 202 and whatever message we want; which is in this case "Data not ready".
The solution that I've found is the following:
When the status is returned as 202, I'm stopping the datatable load and calling a recursive function that will keep checking for the server status:
The recursive function:
Table reload function:
that's a cool approach, but doesn't it tend to take over the browser while it recurses? If I had to deal that that, I'd probably use SetInterval().
That is exactly what I was doing, but we already have a delay on the server, which also allows me to abort the AJAX call in progress if i need to re-sort the table by another column (which calls a different tableURL). There's nothing else to do on the page while the stats are loading, so the taking over the browser is not an issue at this point.
Hi,
That looks like a good approach to me. The other option would be to use
ajax
as a function and make your own Ajax calls - continue to do so (in a simple recursive loop as you have) until a 200 is returned and then finally trigger the success callback.One more option is to do the Ajax externally to DataTables and use
rows.add()
when the data is ready.Regards,
Allan
That's a great idea. Thanks!