我使用javascript设置了cookie值,然后我想使用php检索刷新的cookie值…但是我的cookie值变老了,谁能把我的解决方案贴在这里?下面是代码:
onClick="javascript:document.cookie='title=< ?php echo $title; ? >';"
和代码检索cookie..但不刷新:
<?php $tit=$_COOKIE['title']; ?>
所以当我回显$tit;
时,我得到旧值…谁能在这里发布刷新cookie值的解决方案并将其读取到php变量$tit
正如@datasage指出onMouseDown
在onClick
之前被调用,所以你的addHit
javascript在设置cookie值之前运行。详情请看此页
使用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>