Problem storing data in a cookie...

G

Griff

Hi

I have an HTML search page that contains a drop-down box with
approximately 78,000 items in it.

The actual content of this select box varies depending upon some of the
parameters a user has chosen, so this needs to be loaded (possibly
several times as they change their parameters) and I've got this
working using AJAX.

However, as you can well imagine, this takes quite some time to get
this data from the database and turn into the select box.

To cut down time, I've put this in the Session("xxx") object held on
the server and this manages to cut it down from 15 seconds to 10
seconds. This tells me that it simply takes quite a lot of time to
transfer this data around the internet.

So...what I'd REALLY like to do is to save it to a cookie. Now, I've
found several examples on the web of how to write and read from cookies
but unfortunately it's not working in my hands. I suspect that it's
something to do with the value for the cookie...

The value would be something like this ("...." implies multiple lines).

value = "Please select a product code &nbsp;nbsp;<select
name=""x""><option
value=""y"">y"</option>.....</select>&nbsp;&nbsp;78,000products
available".

Any ideas/suggestions would be most appreciated

Griff
 
G

Griff

Just to provide some more info....

The JavaScript function that updates the web page AND *attempts* to set
the cookie's value is as follows:

function xmlHttpChange()
{
if (XmlHttp.readyState==4)
{
// Load the response text into a local variable
productCodeData = XmlHttp.responseText;

// Update the web page with this data

document.getElementById('ProductCodeSelection').innerHTML=productCodeData;

// Save to cookie (e.g. "myAppName_Acme_1234")
var cookieName = "myAppName_" + document.getElementById

('accountName').value + "_" +
document.getElementById('userID').value;

document.cookie = cookieName+"="+escape(productCodeData);

XmlHttp=null;
}
}

When I check whether anything is held in the cookies, I put in the
following alert:

alert("document.cookie.length = " + document.cookie.length);

This returns ""document.cookie.length = 0"

Something's not quite right here....

Griff
 
L

Laurent Bugnion

Hi,
Hi

I have an HTML search page that contains a drop-down box with
approximately 78,000 items in it.

The actual content of this select box varies depending upon some of the
parameters a user has chosen, so this needs to be loaded (possibly
several times as they change their parameters) and I've got this
working using AJAX.

However, as you can well imagine, this takes quite some time to get
this data from the database and turn into the select box.

To cut down time, I've put this in the Session("xxx") object held on
the server and this manages to cut it down from 15 seconds to 10
seconds. This tells me that it simply takes quite a lot of time to
transfer this data around the internet.

So...what I'd REALLY like to do is to save it to a cookie. Now, I've
found several examples on the web of how to write and read from cookies
but unfortunately it's not working in my hands. I suspect that it's
something to do with the value for the cookie...

The value would be something like this ("...." implies multiple lines).

value = "Please select a product code &nbsp;nbsp;<select
name=""x""><option
value=""y"">y"</option>.....</select>&nbsp;&nbsp;78,000products
available".

Any ideas/suggestions would be most appreciated

Griff

It might be due to the size. A cookie can contain maximum 4KB, IIRC. I
am not sure what the behaviour is if you try to store a longer string.

I posted my CCookie object on my website, it's an abstraction of the
cookie API which allows you to call methods instead of manipulating the
cookie string. It also has methods allowing to check if session cookies
and/or permanent cookies are enabled. The code is self-documented.

http://www.galasoft-lb.ch/myjavascript/CCookie/index.html

HTH,
Laurent
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,280
Latest member
BGBBrock56

Latest Threads

Top