Javascript 如何在jquery中设置url中的cookie
我需要什么Javascript 如何在jquery中设置url中的cookie,javascript,php,jquery,symfony,cookies,Javascript,Php,Jquery,Symfony,Cookies,我需要什么 我需要在jquery的url中附加cookie数据 Php Public function get_hash_attend($event_id,$user_id) { echo $event_id; echo "<pre>"; echo $user_id; $key = '!@#hjka@#$jks*&@'; $encrypt=$user_id."-".$even
- 我需要在jquery的url中附加cookie数据
Public function get_hash_attend($event_id,$user_id)
{
echo $event_id;
echo "<pre>";
echo $user_id;
$key = '!@#hjka@#$jks*&@';
$encrypt=$user_id."-".$event_id;
$encrypted = mcrypt_encrypt(MCRYPT_RIJNDAEL_256, $key, $encrypt, MCRYPT_MODE_ECB);
$xyz = (base64_encode($encrypted));
$xyz = urlencode($xyz);
$xyz = str_replace("%2F",")",$xyz);
$xyz = str_replace("%3F","_",$xyz);
$xyz = str_replace("%2B","(",$xyz);
$hash='http://'.DOMAIN_NAME.'/ticket_transaction/autosubmit_advance/'.$event_id.'/'.$user_id.'/'.$xyz.'?source=oneclickEmail';
return $hash;
//$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $d, MCRYPT_MODE_ECB);
}
公共函数get\u hash\u attent($event\u id,$user\u id)
{
echo$event\u id;
回声“;
echo$user\u id;
$key='!@hjka#$jks*&';
$encrypt=$user\u id.“-”$event\u id;
$encrypted=mcrypt_encrypt(mcrypt_RIJNDAEL_256,$key$encrypt,mcrypt_MODE_ECB);
$xyz=(base64_编码($encrypted));
$xyz=urlencode($xyz);
$xyz=str_replace(“%2F”,”,$xyz);
$xyz=str_replace(“%3F”、“_”、$xyz);
$xyz=str_replace(“%2B”,”(“,$xyz”);
$hash='http://'.DOMAIN\u NAME./ticket\u transaction/autosubmit\u advance/'.$event\u id./'.$user\u id./'.$xyz.'source=oneclickEmail';
返回$hash;
//$decrypted=mcrypt_decrypt(mcrypt_RIJNDAEL_256,$key,$d,mcrypt_MODE_ECB);
}
js代码
$(文档).ready(函数()
{
$(“#出席”)。单击(函数(){
警报(“出席。单击()”;
$.ajax({
类型:“POST”,
网址:“{{get_hash_attent(913530767)}”,
成功:功能(数据)
{
警报(数据);
$(“出席”).text(“出席”);
//警报(数据);
}
});
});
});
我面临的问题
- 当我使用url时:{{{get_hash_attent(913530767)}}效果很好
- 但当用户保存在cookie中时,如何获取cookie数据
- 我有$data[$k]['event_id']在细枝中
- 我需要从函数中的cookie中获取用户数据
- 特定url的id
您想在jquery中读取cookie值吗?我在浏览器中设置了cookie如何获取cookie并在url$中设置。如果您使用@dtelaroli在回答中建议的插件,cookie('cookie name')将为您提供cookie值。我尝试了$.cookie('user',user');请尝试$.cookie('user')。没有插件是否可能
<script>
$(document).ready(function()
{
$( "#attend" ).click(function() {
alert( "attend .click() ." );
$.ajax({
type:"POST",
url:"{{get_hash_attend(9,13530767)}}",
success: function(data)
{
alert(data);
$("#attend").text("Attending");
//alert(data);
}
});
});
});
</script>