Ajax polling crashing the browser as its memory usage,cpu utilization continously increasing ? Any alternative

StackOverflow https://stackoverflow.com/questions/15815221

문제

I am new to the ajax polling and i implemented to fetch data continuously , But the problem i am getting is Memory usage and CPU utilization is continously keep on increasing and in the last the browser is crashing . Here is ajax call what i am using to fetch data continuously .

$(document).ready(function () {

make_call();
function make_call() {
$.ajax({
url: "url",
              accepts: "application/json",
              cache: false,
              success: function (result) { // Some code here },
complete: make_call
});
}
}

Is there any other alternative , or am i doing something wrong . Please provide some suggestion or solution . Thanks in advance .

도움이 되었습니까?

해결책

Your code initializes a new request at the same moment the previous requests completes (complete being either an error or success). You likely want to have a small delay before requesting new data - with the benefit of reducing both server and client load.

$.ajax({
  // ...
  complete: function() {
    setTimeout(make_call, 5000);
  }
});

The above code waits for 5 seconds before making the next request. Tune the value to your needs of "continuous".

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top