Posts

Showing posts from May, 2021

Ajax to auto populate table data periodically

Image
 Let's consider below use case. The train schedule is adjusted by the control room and exposed as a REST API to be displayed at each train station in near real time. So show the updated details to their passengers, these train station displays should call this REST API in a reasonable frequency and update the information. Below implementation shows how this can be achieved using Ajax technique. This can be used to any similar use case. The full sample code can be located at https://github.com/kladrock/ajax-sample-auto-refresh-table . To simulate the response from the train schedule REST API, we use this, https://raw.githubusercontent.com/kladrock/klad-rocks/main/trains.json . First we need to call get the data from the REST API. It's done in the below code segment. function loadData() { $("#example").DataTable(); $.ajax({ type: 'GET', url: testDataUrl, contentType: "text/plain", dataType: 'json',