DataTables displays stale data due to out‑of‑order Ajax responses
0 reputation · 18 Jul 2023, 21:20 UTC
Goal: Ensure that a DataTables instance in server‑side mode displays only the data from the most recent Ajax request, preventing stale data from appearing when earlier requests finish after later ones.
Constraints: DataTables does not automatically abort previous Ajax requests when a new draw is triggered, so overlapping requests can race; developers must keep a reference to the prior jqXHR and call .abort() themselves, which is not a documented built‑in feature. Timeout handling depends on the global jQuery Ajax timeout setting (via jQuery.ajaxSetup or jqXHR.timeout), affecting all Ajax calls on the page. Furthermore, DataTables relies on the draw parameter to order responses, but if the server ignores or mismatches draw values there is no automatic detection or error, allowing out‑of‑order responses to update the table silently.
Questions: How can developers reliably cancel prior Ajax requests without introducing server‑side side effects? Is there a way to configure DataTables to discard responses with stale or mismatched draw values? Should DataTables provide an instance‑scoped timeout option instead of relying on global jQuery settings?