[Javascript] AJAX + Cookies

Philip Thompson philthathril at gmail.com
Mon Jun 16 15:54:49 CDT 2008


On Jun 16, 2008, at 3:41 PM, Matt Warden wrote:

> On Mon, Jun 16, 2008 at 4:36 PM, Philip Thompson <philthathril at gmail.com 
> > wrote:
>> Hi all.
>>
>> I've been hitting my head against the wall for a while now. I've
>> gotten a few hits from Google, but nothing has really answered my
>> question:
>>
>> After updating the value of a cookie during an AJAX request, can that
>> value be immediately accessed via the cookie (w/o a new request)?
>>
>> [js]
>> alert(readCookie('mycookie'));
>> updateCookie('mycookie', 'newValue');
>> alert(readCookie('mycookie'));
>> [/js]
>
> You need to be reading the cookie value of the document returned in
> the AJAX response. It will not update the document.cookie where
> document refers to the containing document which issued the AJAX
> request.

Matt, thanks for your prompt response. However, I'm not sure I follow.  
Is this what you mean...

Document 1:
Makes AJAX call to Document 2 that does stuff and updates the cookies

Document 2:
Updates the cookies and sets the new values and returns stuff to  
Document 1

Are you saying that the new cookie values are only accessible by  
Document 1 at this point? If not, can you please elaborate?

Thanks,
~Philip



More information about the Javascript mailing list