Hi I have script below: Basically I have a navigation anchors “next” and “prev” which increments or decrements currentDate to navigate between days. This means variable currentDate cannot refresh once the page is load. This variable should be like static variable which should maintain its state, however when ajax call comes back this variable is updated each time to new Date().
<script>
var currentDate = new Date();
$(document).ready(function() {
//ajax call to retrieve some values from the server
});
</script>
Is it possible to declare a global variable which doesn’t refresh with each ajax call? Or is it better to get the updated date from the server in this situation? Or am I handling this situation wrongly?
Thanks!
The global javascript variable would not normally reset to “new Date()” simply because an AJAX call returns. It would reset if the page is refreshed. Are you sure there isn’t a windows.location call or something else in your AJAX return handler that refreshes the page?