Need some help with a coding issue I'm facing. Can anyone provide suggestions for improving my code?
I've come across a situation where the table is not updating when using a certain piece of code. However, upon further inspection, I found that moving the TableList = {}
into the success function resolves the issue and updates the table as intended.
Could someone please explain why it's necessary to move the emptying of the object into the success block?
The explanations I've come across so far haven't been very helpful in clarifying this for me.
function GetTableData() {
TableList = {};
$.ajax({
url: "http://localhost:3000/info/",
success: function (result) {
//Moving 'TableList = {}' here works fine
for (var i = 0; i < result.length; i++) {
TableList[i] = result[i];
}
}
});
}
function UpdateTable() {
GetTableData()
//Update table cells
setTimeout(function () {
UpdateTable();
}, 1000);
}