duanhuan3012 2013-05-14 03:14
浏览 44
已采纳

使用javascript或php脚本清除cookie

i have a problem need all you guys help me.i set the cookie with javascript when the user make change to the select tag in html code and clear i want to clear it.

* if in php script i just need to clear or delete it , but if in jquery script i need to delete the old one immediately and set a new one of cookie value when the user make change to select tag. let's see the script below.

jquery script

<script type="text/javascript">
  $(function(){
     $('#category').live('change',function(){
       var opt = $('category :seleted').val();
       document.cookie='category_name='+opt; //set the cookie when user make change
       $.ajax({
         type:'POST',
         url : 'getcatetgory.php',
         data : {option : opt},
         success: function(){alert('you have successfully get on category')}
      });
    });
  });
</script> 

html

<select id='category'>
  <option value='car'>Car</option>
  <option value='house'>House</option>
  <option value='sport'>Sport</option>
  <option value='song'>Song</option>
  <option value='phone'>Phone</option>
</selete>

this is i have done with php script.

unset($_COOKIE['category_name']);

but it still doesn't work for me. please guide me

  • 写回答

1条回答 默认 最新

  • duan19911992 2013-05-14 03:15
    关注

    To delete a cookie, you must set a cookie with the same name, path and domain, but with an expiry date that is in the past.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器