My current project involves fetching data from a database in c# and passing it to Javascript using Ajax. I store this data in arrays and query the database every 3 seconds. The data is utilized to update a diagram, such as changing the color of the track. The simulation functions smoothly up to 30 seconds, but after that point, the UI (browser) becomes unresponsive and fails to update. I am seeking advice on how to keep the simulation running smoothly without causing the UI to freeze.
Code :
function getData() {
$(document).ready(function () {
var q = setInterval(getData, 3000);
jQuery.ajax({
type: "POST",
url: "WebForm1.aspx/GetStations", //Calling the web method
contentType: "application/json; charset=utf-8",
data: JSON.stringify({ myArray: dl_id_track }),
dataType: "json",
async: true,
success: function (data) {
if (data != null) {
var len = data.d.length;
for (var i = 0; i < len; i++) {
signo[i] = data.d[i].signo;
status[i] = data.d[i].status;
}
}
simulate();
},
error: function (d) {
}
});
});
}
function simulate() {
for (var i = 0; i < b.length; i++) {
for (var j = 0; j < 1024; j++) {
//track
if (signo[j] == sig_no_track[i]) {
if (status[j] == "1") {
var x1 = parseInt(left_track[i]) + parseInt(x1_track[i]);
var y1 = parseInt(top_track[i]) + parseInt(y1_track[i]);
var x2 = parseInt(left_track[i]) + parseInt(x2_track[i]);
var y2 = parseInt(top_track[i]) + parseInt(y2_track[i]);
var line1 = draw.line([[x1, y1], [x2, y2]]).stroke({ width: 3, color: '#ff0000' });
}