此脚本中未设置 jQuery cookie
我正在尝试扩展此脚本 允许处理多个页面。
我不想使用单个时间戳,而是使用像这样的逗号分隔列表: 1305536229613,1305536315210,1305536318026
问题是脚本服务器端正确设置 cookie 但 js 代码不起作用(至少在Opensuse 11.3 上的 Firefox 3.6.17)。
我必须在设置时间间隔之前添加 $.cookie(cookieName, null)
(!) 才能让 cookie = $.cookie(cookieName);
工作在下面两行。 ..(我是怎么找到它的,我不知道......)。
此外,更新 cookie 不起作用:我可以在另一个页面中使用服务器脚本 cookie 看到它总是在增长,
$(document).ready(function(){
var cookieCheckTimer;
var cookieName = 'download_token';
var $wait = $('.wait');
var $waitMsg = $('<span>Processing, please wait...</span>').prepend(
$('<img />').attr('src', '/img/wait.gif').css({
'vertical-align': 'middle',
'margin-right': '1em'
}));
//add hidden field to forms with .wait submit
$wait.parent().each(function(){
$(this).append($('<input />').attr({
'type': 'hidden',
'name': cookieName,
'id': cookieName
}));
});
$wait.click(function(){
var token = String(new Date().getTime());
//set token value
$('#' + cookieName).val(token);
//hide submit buttons
$(':submit').hide();
//append wait msg
$(this).after($waitMsg);
//why?? don't know...
$.cookie(cookieName, null) //<<<<<<<<<<
//set interval
cookieCheckTimer = window.setInterval(function(){
var cookie = $.cookie(cookieName);
if (cookie != null){
cookie = cookie.split(',');
var idx = cookie.indexOf(token);
if (idx >= 0){
//detach wait msg
$waitMsg.detach();
//show again submit buttons
$(':submit').show();
//remove token
cookie.splice(idx, 1);
//clear timer
window.clearInterval(cookieCheckTimer);
//update cookie value
if (cookie) $.cookie(cookieName, cookie.join(','));
else $.cookie(cookieName, null);
}
}
}, 1000);
});
});
I'm trying to extend this script to allow working with multiple pages.
Instead of using a single timestamp I want to use a comma-separated list like this: 1305536229613,1305536315210,1305536318026
The problem is the script server side sets cookies correctly but js code does not work (at least in Firefox 3.6.17 on Opensuse 11.3).
I had to add $.cookie(cookieName, null)
(!) before setting time interval to get cookie = $.cookie(cookieName);
to work 2 lines below... (how did I found it I don't know...).
Moreover updating the cookie does not work: I can see in another page using a server script cookie always growing
$(document).ready(function(){
var cookieCheckTimer;
var cookieName = 'download_token';
var $wait = $('.wait');
var $waitMsg = $('<span>Processing, please wait...</span>').prepend(
$('<img />').attr('src', '/img/wait.gif').css({
'vertical-align': 'middle',
'margin-right': '1em'
}));
//add hidden field to forms with .wait submit
$wait.parent().each(function(){
$(this).append($('<input />').attr({
'type': 'hidden',
'name': cookieName,
'id': cookieName
}));
});
$wait.click(function(){
var token = String(new Date().getTime());
//set token value
$('#' + cookieName).val(token);
//hide submit buttons
$(':submit').hide();
//append wait msg
$(this).after($waitMsg);
//why?? don't know...
$.cookie(cookieName, null) //<<<<<<<<<<
//set interval
cookieCheckTimer = window.setInterval(function(){
var cookie = $.cookie(cookieName);
if (cookie != null){
cookie = cookie.split(',');
var idx = cookie.indexOf(token);
if (idx >= 0){
//detach wait msg
$waitMsg.detach();
//show again submit buttons
$(':submit').show();
//remove token
cookie.splice(idx, 1);
//clear timer
window.clearInterval(cookieCheckTimer);
//update cookie value
if (cookie) $.cookie(cookieName, cookie.join(','));
else $.cookie(cookieName, null);
}
}
}, 1000);
});
});
I'm using latest version of the jquery.cookie plugin from repository
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论