javascript - Why are my cookies randomly changing? -


introduction

i working on app rails 4 functions simple dashboard, iterates through several div containers sectioned off in quadrants on home page show various graphs/tables etc. using cookies remember index current displayed container @ when website reloads displays container being shown , not go first one.

the problem

everything seemed working ok until started noticing cookies started changing , have no idea how. have come conclusion since set , cookies using function, prints console whenever being called. , nothing being logged console when these "rogue" changes occur.

here's gist of how works. update function uses helper function cookie, calculates next index depending on current index is, , calls helper function store cookie. cookies , set 2 functions.

var update_quadrant = function(id) =   $.when(get_cookie(current_feed)).done(function(response) {       var current_index = parseint(response);       var next_index = //depends on current_index      $.when(store_cookie(current_feed, next_index, "from update")).done(function(response){           //code updates quadrant            settimeout(function() { update_quadrant(id);}, 30000);       }); 

here's typical cookies like.

{"circleci" => "0", "newrelic" => "1", "googleanalytics" => "0"} 

javascript

storing cookie value

var store_cookie = function(feed, value, other) { return $.ajax({     url: 'home/cookie_store',     type: 'post',     data: {         feed: feed,         value: value,         other: other || ""     }     }).done(function(response) {     console.log(response);     }); }; 

getting cookie

var get_cookie = function(feed) {     return $.ajax({         url: 'home/cookie_get',         data: {             feed: feed         }     }).done(function(response) {     console.log("got cookie value: ", parseint(response), "for ", feed);     }); }; 

controller

responding ajax call store cookie value

#home controller  def store_cookie     feed = params[:feed]     value = params[:value]     other = params[:other]     cookies[feed] = value.to_s     render text: "stored #{value} #{feed}, other: #{other}"  end 

responding ajax call cookie value.

#home controller  def give_cookie      feed = params[:feed]     cookies[feed] = "0" if cookies[feed].blank?     render text: cookies[feed.to_s]  end 

what i've tried test

i thought maybe somehow settimeout function persisting, , multiple settimeout timers being executed doesn't change fact values changing without being logged console store_cookie function.

for example, set setinterval logs document.cookie console every second. here's display.

 "stored 0 circleci, other: update quadrant"  //correctly changed store_cookie function logs response controller {"circleci" => "0", "newrelic" => "1", "googleanalytics" => "0"} ...//no change ...//no change ...//no change {"circleci" => "1", "newrelic" => "1", "googleanalytics" => "0"} //but nothing printed console store_cookie function  //quadrant goes update after 30 seconds, , gets wrong cookie value "got cookie value: 1 circleci" //should 0 not 1 

even more baffling, when go click link uses layout doesn't include javascript source files cookie values still being changed.

i have been struggling idea of start debugging since have double , triple checked make sure cookie changes on code side changed store_cookie function , i'm seeing these cookie values being changed without being logged console, aka without store_cookie function being called.

does have idea whats causing cookie values seemingly change themselves?


Comments

Popular posts from this blog

javascript - Using jquery append to add option values into a select element not working -

Android soft keyboard reverts to default keyboard on orientation change -

Rendering JButton to get the JCheckBox behavior in a JTable by using images does not update my table -