ajax - PHP Session Array -
i'm trying sketch out easiest way pass integers array when button/href clicked. need access array globally on page.
do have ajax or possible in 1 file through session array?
thanks pointing me in right direction.
-jonathan
i suggest using client side tehcnology such localstorage or cookies instead.
the main reason that, if trying track clicks on buttons , links php, need send new http request every time can track on php $_post
or $_get
. while can obvious link, hurt user experience when comes buttons (that not form submit buttons).
assuming want avoid refershing page on every button click, need implement ajax. leads folllowing question - if using javascript , ajax, why not track in javascript first place , communicate server when needed?
client side tracking localstorage
:
by using localstorage
or cookies
, can bind events clicks , save array.
in javascript/jquery can use following examaple:
$(document).ready(function() { var urls = json.parse(localstorage["visited"]) || [];//get visited urls local storage or initialize array if (urls.indexof(document.url) == -1) {//if current url not exist in array urls.push(document.url);//add array localstorage["visited"] = json.stringify(urls);//save stringifyed version of array local storage } });
by having array data in javascript can more manipulate dom , css without dependency on server. (i.e changing link's text, href or css if clicked).
hope helps!
Comments
Post a Comment