[英]Send / receive data from js / jQuery
I have a problem, I'm building my own player on website. 我有一个问题,我正在网站上建立自己的播放器。 And I have some data (2 variables) from js/jQuery and I want to send it anywhere I click (other pages of my site).
我有一些来自js / jQuery的数据(2个变量),我想将其发送到我单击的任何位置(我网站的其他页面)。 I thought that the cookies are good idea but its not, sending by post - I don't know how.
我认为cookie是个好主意,但不是,通过邮寄发送-我不知道如何。
Please give some tips. 请给一些提示。
var cookieValue = $.cookie("czasplajera", { path: '/' });
$("#info").html(cookieValue);
$("#jquery_jplayer_1").jPlayer("play",parseInt(cookieValue));
$("#jquery_jplayer_1").bind($.jPlayer.event.timeupdate, function(event) {
var czasplajera = Math.floor(event.jPlayer.status.currentTime);
//$('#info').html(czasplajera);
$.cookie("czasplajera",czasplajera, { expires: 1, path: '/' });
});
When you are reading a cookie value, you only supply one argument, the key: 在读取Cookie值时,您仅提供一个参数,即键:
var cookieValue = $.cookie("czasplajera");
Working demo: http://jsfiddle.net/jfriend00/K5AgD/ 工作演示: http : //jsfiddle.net/jfriend00/K5AgD/
When you pass more than one argument, the cookie library things you are trying to set a cookie value: 当您传递多个参数时,cookie库将尝试设置cookie值:
var cookieValue = $.cookie("czasplajera", "whateverValue", { path: '/' });
When you do this (which is what your code is doing): 当您执行此操作(这就是您的代码正在执行的操作):
var cookieValue = $.cookie("czasplajera", { path: '/' });
the jQuery plugin is probably trying to set a cookie value and isn't returning anything useful so your first line of code above is not reading the cookie value. jQuery插件可能正在尝试设置Cookie值,并且未返回任何有用的信息,因此您上面的第一行代码未读取Cookie值。
Also, since the cookie functionality is not built into jQuery (it's a separate plug-in), you have to make sure you have the code loaded for the cookie plugin. 另外,由于cookie功能未内置在jQuery中(它是一个单独的插件),因此必须确保已为cookie插件加载了代码。
Are you sure the cookie is set: 您确定Cookie已设置:
$.cookie("CookieName", "Cookie Value");
Then you can retrieve data inside with: 然后,您可以使用以下命令检索内部数据:
$.cookie("CookieName");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.