我已经使用javascript设置了cookie值,然后我想使用php检索刷新的cookie值...但是我得到了cookie的旧值...有人在这里发布我的解决方案...这里是代码:< / p>
onClick="javascript:document.cookie='title=< ?php echo $title; ? >';"
和用于检索cookie的代码..但未刷新:
<?php $tit=$_COOKIE['title']; ?>
所以当我回显$tit;
时,我得到了旧的价值......有人可以在这里发布解决方案以刷新cookie值并将其读取到php变量$tit
答案 0 :(得分:1)
@datasage指出在onMouseDown
之前调用onClick
,因此在设置Cookie值之前运行addHit
javascript。有关详细信息,请参阅this page
使用php回显您的链接
<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>
使用jQuery将事件处理程序附加到每个链接
<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>