Why the data is hidden when the page refresh?

Hy,

I have timer in my meteor app, it does work correctly like in the pic bellow : 00:11

weirdly; it stops working and display “Nan” when I refresh the page like in this pic

my code is included in event helpers

‘click .myButton’: function () {
var lll = Session.get(‘nombreL’);
function Kounter(){
if (lll == 0) {
return 30;
}else if (lll == 1) {
return 25;
};
}
var time=Kounter(),r=document.getElementById(‘h2’),tmp=time;
intervalId = setInterval(function(){
var c=tmp–,m=(c/60)>>0,s=(c-m*60)+’’;
Session.set(‘times’, c+1);
r.textContent=" بقى من الثواني : "+m+’:’+(s.length>1?’’:‘0’)+s
tmp!=0;
if (Session.get(‘times’) <= 0) {
delete Session.keys[‘times’];
clearInterval(intervalId);
Router.go(‘over’);
};
}, 1000);
}

Could any one, please, help me to understand what happen when the page is refreshed? how to fix it ?

Thank’s a lot

Your code is only called when the button is clicked.
When you refresh, you go back to the situation before clicking.

What is the code in the template file?

@xavierpriour; the pic above is taken after I click the button; after the page is refreshed;

in the template of timmer there is only this

{{min}} (دقائق) : {{sec}} (ثواني)

wich is rendred by helper, the result; like

min: function () {
var nom = Meteor.user().services.facebook.name;
var ad = Meteor.userId();
var endtime = NPortes.findOne({userID:ad}).date_created;
var lastR = Session.get(“time”) - endtime;
Session.set(“temps”, lastR);
var min = (lastR/1000/60) << 0;
if (endtime ||lastR > 0) {
return min;
};
},
sec: function () {
var nom = Meteor.user().services.facebook.name;
var ad = Meteor.userId();
var endtime = NPortes.findOne({userID:ad}).date_created;
var lastR = Session.get(“time”) - endtime;
var sec = Math.floor((lastR/1000) % 60);
if (endtime ||lastR > 0 ) {
return sec;
};

Thank’s

I would say your Kounter function returns a NaN - maybe your var III is undefined? Session[‘nombreL’] being reset somewhere else in your code when you refresh? You should be able to find out quickly by debugging in the console.

Happy hunting!

1 Like

@xavierpriour thanks, i ll check that

1 Like