Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

remove Cookie using jquery not working

Tags:

I have two cookies in my JS file and I want to remove them.

I have tried the code below but it is not working

 $.removeCookie('filter', { path: '/Home/' });  $.removeCookie('Pfilter', { path: '/Home/' }); 

I have also tried the below for null cookies, but this is also not working.

Thanks for the help

$.cookie('filter',null, { path: '/Home/' }); 
like image 395
Mahesh Gaikwad Avatar asked Aug 28 '13 11:08

Mahesh Gaikwad


People also ask

How to delete cookie in JQuery?

This can be done using the cookie() and removeCookie() methods of the jquery-cookie library.

Why are my cookies not deleting?

If you created it with a path / and a domain mydomain.com, then you have to delete it with those. If you did not use path or domain when creating the cookie, you can not have the path or domain when deleting it. Trick was to delete it in the EXACT same way it was created.


2 Answers

It might depend on what path your cookie is using. If you goto the chrome developer tools and check the path column under Resources > Cookies > Path.

enter image description here

You might be using the generic / for your path instead of /Home/. Give the code below a try.

To delete a cookie with jQuery set the value to null:

$.removeCookie('filter', { path: '/' }); 
like image 53
Mark Avatar answered Oct 12 '22 11:10

Mark


Did you try $.cookie("name", null);

$.removeCookie('filter', { path: '/' }); 
like image 26
Ravi Vanapalli Avatar answered Oct 12 '22 10:10

Ravi Vanapalli