-
XML and Cookies
Hello,
Just wondering if you can store a XML file into a Cookie?
I have the following code:
Code:
function setCookie(c_name,value,exdays)
{
var exdate=new Date();
exdate.setDate(exdate.getDate() + exdays);
var c_value=escape(value) + ((exdays==null) ? "" : "; expires="+exdate.toUTCString());
document.cookie=c_name + "=" + c_value;
}
just wondering if you can store a XML file into a cookie so that I can load the whole xml file from the cookie rather than loading the XML file again?
Anyone able to help?
-
Re: XML and Cookies
Sorry. Cookies store raw strings. You could use JSON and serialize the XML as an object, then convert back to XML after. But, either way...you're still dealing with plain text.
-
Re: XML and Cookies
Agree with but you can set the timeout of the cookie. This is temporary solution yet.
-
Re: XML and Cookies
While you can store XML text in a cookie, it might not be the best idea.
XML means a lot of overhead and if you want to store a lot of data, you can reach the 4 KB limit quickly.