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.

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

报告相同问题?