jquery - Javascript setInterval with ajax call making site slow -


i have implemented setinterval() function in javascript makes ajax call in every 2 minutes. ajax call returns data append in html. don't know why makes website slow, gradually. website developed in node js. googled issue , got know clearinterval() function. unable use properly. can give me generic example of clearing interval properly? or other issue related node js?

code below:

setinterval(function() {     appenddata(skipcount);}, 120000);  function appenddata(_popularskipcount) {     var cookievalue = $.cookie('type');              var _data = {         "limit": defaultlimit - 1,         "skipcount": _popularskipcount     }                    $.ajax({         type: "get",         url: "/popular/" + cookievalue,         data: _data,         async: true,         success: function (data) {               $("#data-box").empty();             if($(data).size() > 0) {                 for(var = 0; < $(data).size() ; i++) {                     var html = "<div class='large-12 columns popular'><img class='image' src='" + $(data)[i].url + "' class='popular-img'><a href='/abc/" + $(data)[i].slug + "'><h4>" + name + "</h4></a><h5>" + city + "</h5></div>";                     $(html).hide().appendto("#data-box").fadein(1000);                 }             } else {                 appenddata("0");             }                        },         error: function(jqxhr, textstatus, errorthrown) {                                          $("#data-box").empty();             console.log(errorthrown);         }     });      }; 

the clearinterval() method clears timer set setinterval() method.

below 1 example code

var myvar = setinterval(function(){ setcolor() }, 300);  function setcolor() {     var x = document.body;     x.style.backgroundcolor = x.style.backgroundcolor == "yellow" ? "pink" : "yellow"; }  function stopcolor() {     clearinterval(myvar); } 

Comments

Popular posts from this blog

php - failed to open stream: HTTP request failed! HTTP/1.0 400 Bad Request -

java - How to filter a backspace keyboard input -

java - Show Soft Keyboard when EditText Appears -