使用jQuery Cookie插件时遇到问题 我有5-10 div标签与class .buttonplay 当点击每个标签时,我使用ajax发布一个php文件结束返回结果。 但是由于每次点击都会从mysql传输大量数据。我想将数据存储在cookie中存储1天。但只有第一个元素奏效。其他元素不存储任何cookie。 码: div标签
<div id='oneclick' idbutton='1' class='buttonplay' data-name='amf_fb-like-page'>RUN Facebook like page <span> <i class='fa fa-play-circle'></i> </span></div>
<div id='oneclick' idbutton='2' class='buttonplay' data-name='amf_fb-like-post'>RUN Facebook like post <span> <i class='fa fa-play-circle'></i> </span></div>
<div id='oneclick' idbutton='3' class='buttonplay' data-name='amf_fb-share-post'>RUN Facebook share post <span> <i class='fa fa-play-circle'></i> </span></div>
Js代码:
function error_find(html){
if (html.indexOf('Could not') != -1){
alert("Sorry, Error happened. <br />Please comment the following code in the comment box bellow. <br /><pre>"+html+"</pre>");
return false;
}else{
return true;
}
}
$(".buttonplay").click(function(){
var id_code=$(this).attr('idbutton');
var cookie_name = $(this).attr('data-name');
var cookie_text = $.cookie(cookie_name);
if (!cookie_text){
$.ajax({
type: "POST",
url: "data.php/?data=run",
data: {id_code: id_code},
dataType: "text",
success:function(html){
if (error_find(html)){
alert('new');
$.cookie(cookie_name, html, { expires: 1 });
window.location.href=html;
}
}
});
} else {
window.location.href=cookie_text;
alert('old');
}
});
对于实例:此处(http://social.tienganhratde.com/index.php?page=1&id=1)