javascript - Why this polling stops working after idling for some time? -


i using angularjs poll new data through http post. alert sent when new data received. code inside controller looks this;

    var poll = function() {         $http.get('phones.json').success(             function(data)             {                 new_val = data.val;                 if ( (new_val!== old_val) )                 {                     $window.alert("alertevent");                                         }                  old_data = new_val;                 $timeout(poll, 500);             }         );     };     poll();    

this code works when html page refreshed. working means when phones.json changed, alert appear. however, if leave page on for, 30 minutes, , come later, stops working. have refresh page working again.

what else did miss out? did wrong? due caching mechanism?

thank much.

edit: found cause. indeed due browser reading cache. can see using chrome developer tools. how can caching disabled html page only?

you may able bust cache doing this:

 $http.get('phones.json?v=' + date.now()) 

depending on how back-end set-up may need adjust accept that.


Comments

Popular posts from this blog

user interface - How to replace the Python logo in a Tkinter-based Python GUI app? -

objective c - Greedy NSProgressIndicator Allocation -

how to set an OCR language in Google Drive -