Question

I couldn't find an answer on this online so here goes:

I am reading a string from the query string and I am saving it in a cookie using the jquery cookie plugin.

This page may be reloaded a couple of times a day with different ids but it seems to always remember the first value. It seems to be very difficult to get the cookie to change to the new value each time.

$.cookie('SomeId')  // already contains some number from the first time the page was called.

The logic I am attempting to use is this:

if (QueryString.some_id) {
    alert(QueryString.some_id); //shows new Id
    $.cookie('SomeId', null, { expires: -1 }); //Tried deleting old cookie first
    $.cookie('SomeId', QueryString.some_id, { expires: 30, path: '/' }); // Also tried without the path param
    alert($.cookie('SomeId')); // Alerts the OLD id. Previous call didn't work.
}

How can I get the $.cookie('SomeId') to be updatable?

In case it matters, and I suspect it might, I am running these tests by running the project locally using IIS. It's an MVC application.

Thank you

Was it helpful?

Solution

I had this issue a while back. I fixed it by making up a testing domain [i use clientname.loc and make a new one for each project] and put it in your hosts file [C:\Windows\System32\Drivers\etc\hosts].

#existing hosts file entries
127.0.0.1 clientname.loc

Alternatively you could use 127.0.0.1 instead of localhost as apparently that works to.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top