Stagnant User Interface

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' });



                }

Answer №1

I'm not an expert in web development, but it seems like no one else has responded so I'll give it a shot.

Based on my limited knowledge, it appears that there may be a recursive function that could potentially cause an infinite loop, although it might be slow due to the setInterval. I would recommend trying to move the following code snippet to the end of your <script> block:

$(document).ready(function () {
    var q = setInterval(getData, 3000);
});

To test this change, you will need to remove a corresponding }); from the getData function itself.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Each $.each function varies based on the type of object it is iterating

I have encountered an issue with my $.each statement. When it is written like this: $.each($(".permissions"), function (index, element) { ... }).promise().done(function () {...}); everything works fine. However, when I change the $.each statement to: ...

Ways to detect scrolling activity on the v-data-table module?

Are you looking for a way to detect scrolling events on the v-data-table component in Vuetify framework? I am referring to the scenario where the table has a fixed height, causing the table body to scroll. <v-data-table fixed-header :height=400 : ...

Issue with Vuex not functioning properly in Nuxt.js

I'm facing an issue with setting the state in Vuex on my Nuxt.js App. It seems to not be working correctly. So, here is how I am trying to set the state using the fetch method: fetch({app, store, route}) { app.$axios.$get(`apps/${route.params ...

When editing a table row in PHP, the details retrieved are from the last row instead of the intended row

https://i.sstatic.net/v15sc.png I am facing an issue while trying to edit the contents of a row in my database. I have created a table from the database with edit and delete buttons. The delete button works fine with ajax, but when I click the edit button ...

The angular view is lacking a CSS class

index.html: <div ng-view="myview.html"></div> myview.html: <table class="table table-striped table-hover"> <tr> <td>Name</td> <td>Product</td> </tr> <tr ng-repeat="deal in deals" class="clickableR ...

experiment with jest and react-testing-library for testing functions

I'm having trouble accessing a method inside a functional component in React using Jest and react-testing-library. I attempted to use enzyme, but it seems like everything is shifting towards RTL instead. import React from "react"; const simpleCompo ...

Encountering a frustrating internal server error 500 when attempting to insert values from JavaScript into SQL Server within Visual Studio

Here is a JavaScript code that calls a C# webmethod: var _data = { '_mStart': document.getElementById("St_Period").value, '_mEnd': document.getElementById("En_Period").value }; $.ajax({ type: "POST", url: "maps.aspx/my ...

hover effect with fading transition while mouse is still hovering

Is there a way to create a fade-in/fade-out effect on a div without the mouse needing to leave the area? Let me provide a clearer explanation: When the mouse enters the object The object gradually fades in Then, after a delay, the object fades out while ...

Tips for uploading files to C# MVC model with the angular file uploader

One of the elements on my webpage is a basic chat client that I developed. Within this chat client, there are topics, messages within those topics, and the messages can also include files. The structure is organized as follows: List of Topics -> Each T ...

Utilize Javascript to interact with specific Objects

Working with Node.js, I have written a code that produces the following output: entries: [ { data: [Object] }, { data: [Object] }, { data: [Object] }, ... { data: [Object] } ] } null The code snippet is as follows: targetingIdea ...

tips for accessing variables within app.get

Is there a way to make a variable or a set of variables inside app.get accessible throughout the entire project? I am working on capturing information from an SMS text message, organizing it into the "messageData" variable, and then sending it to the "Mess ...

Integrating VBA and C# through JSON for seamless remote communication

I am currently exploring ways to efficiently transfer a string (specifically JSON data) from a VBA data provider to a C# server. The server I am working with already has a sophisticated communication setup with clients. Currently, I am using CORBA IIOP.NE ...

TypeScript maintains the reference and preserves the equality of two objects

Retrieve the last element of an array, make changes to the object that received the value, but inadvertently modify the original last position as well, resulting in both objects being identical. const lunchVisit = plannedVisits[plannedVisits.length ...

Cast your vote once for each post within the Angular application

Currently, users are only able to vote up or down once in general. I would like to allow users to vote up or down once per post. <div ng-repeat="post in posts | orderBy:'-upvotes'"> <span class="glyphicon glyphicon-thumbs-up" ...

An error has been caught in the Angular JS application while using the highcharts-ng module: [$injector:modulerr]

I'm encountering an issue while trying to integrate Highcharts into my Angular/Node/Express application. I am utilizing the highcharts-ng directive available at https://github.com/pablojim/highcharts-ng Every time I run my app, I consistently receive ...

Output the JSON string retrieved from a specified URL

I'm currently working on using ajax to retrieve and parse JSON data from a specific URL. I am looking for assistance on how to store the parsed array into a variable. Any guidance or suggestions would be greatly appreciated. Thank you! function rvOff ...

Guide on building a Dynamic factory in AngularJS

For my project, I need to implement a dynamic factory in AngularJS with a unique name. Here is an example of what I am trying to achieve: function createDynamicFactory(modId) { return myModule.factory(modId + '-existingService', function ...

Tips for maintaining a user's session post-login with Passport and Express JS

I recently set up a node backend using express and integrated Passport for authentication purposes. My application has a route called /login for logging in and another route called /me to retrieve information about the currently logged in user. Below is t ...

Searching for paired values within an array using Javascript or Jquery

In my JavaScript code, I am working with an array called ppts that looks like: var ppts = []; //... ppts.push({x: mouse.x, y: mouse.y}); //... var tmpArr = []; for (var i=1;ppts.length-1; i++) tmpArr.push(ppts[i].x); alert(tmpArr[2]); tmp_ctx.lineTo(pars ...

Angular Commandments: Understanding the Directives

Within my code, there is a specific directive view that I am utilizing: <div class="busy-indicator angular-animate" ng-show="busy"></div> <div class="breadcrumblist" ng-class="atTopLevel ? ['at-top-level'] : null"> <div ...