Reputation: 159
I have set cookie value using javascript and then i would like to retrieve refreshed cookie value using php...but i im getting old value of cookie..can somebody post me here solution...here is the code:
onClick="javascript:document.cookie='title=< ?php echo $title; ? >';"
and code for retrieve cookie..but is not refreshed:
<?php $tit=$_COOKIE['title']; ?>
so when i echo $tit;
i get old value...can somebody post here solution to refresh cookie value and read it to php variable $tit
Upvotes: 1
Views: 519
Reputation: 571
As @datasage points out onMouseDown
gets called before onClick
so your addHit
javascript runs before setting the cookie value. See this page for details
EDIT: I get what you are trying to do now. You will need to create another php file (datagetter.php in my example) to handle directory scanning and returning data in a useful format, I believe everything you want to do cannot happen in one file all at once without reloading the page or adding an ajax handler to the beginning of your php code.
Use php to echo your links
<a href="ftp://<?php echo $source . '/' . $source2 . '/' . $genre . '/' . $title ?>" id="PopUpItUp" class="detail" data-title="<?php echo $title; ?>" data-id="<?php echo $id; ?>"><?php echo $title ?> (Episodes)</a>
Use jQuery to attach event handlers to each link
<script>
$(window).load(function () {
$('.detail').each().mousedown(function () {
//set title cookie access this in php with $_COOKIE['title']
$.cookie('title', $(this).attr('data-title'));
});
$('.detail').each().click(function (e) {
//increment hitcount
var titleid = $(this).attr('data-id')
addHit('./count.php?id=' + titleid , titleid);
//get data to display via ajax call you may want this IN addHit somewhere
//there will be a delay in getting the data you want so display something to show progress while we wait
$("#popup").html("<div><img src='progresshappens.gif' width='25px' height='25px' />");
$.ajax({
url: 'http://yourdomain.com/datagetter.php?id=' + titleid,
success: function(data) {
//Do something with data, probably add to popup window? here is a starting point
//Check into using javascript 'for each' function
$('#popup').html('<div>' + data + '</div>');
},
error: function(request, error, errormessage) {
//show error, something bad happened
$("#messages").html(error + '\n' + errormessage);
}
});
//don't follow link
e.preventdefault();
return false;
});
</script>
Upvotes: 1