PC Review


Reply
Thread Tools Rate Thread

ajax and cookies

 
 
Mr. SweatyFinger
Guest
Posts: n/a
 
      5th Feb 2007
OK I don't understand ajax, but my page makes a quick ajax call to another
page and returns the results.
that works ok.

That other page is supposed to set a cookie.

That doesn't seem to work.

Is that because ajax doesn't send all the headers and cookies, or am i being
a big dumb jerk?



 
Reply With Quote
 
 
 
 
Nathan Sokalski
Guest
Posts: n/a
 
      5th Feb 2007
When AJAX makes a call and recieves a response, the response is not the
sending of a Response object, it is a call to a JavaScript function on the
page using AJAX. Cookies are set when the Response object is set because
what causes a cookie to be set are headers in the HTTP. Because the Response
object, which is what the other page is setting the headers in, does not get
sent, you are never actually telling the browser to set the cookies. I will
admit that I am not yet an expert in AJAX, but I think that this is if not
the exact reason for your problem, it has something to do with the reason
and should help you find it. Good Luck!
--
Nathan Sokalski
(E-Mail Removed)
http://www.nathansokalski.com/

"Mr. SweatyFinger" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> OK I don't understand ajax, but my page makes a quick ajax call to another
> page and returns the results.
> that works ok.
>
> That other page is supposed to set a cookie.
>
> That doesn't seem to work.
>
> Is that because ajax doesn't send all the headers and cookies, or am i
> being a big dumb jerk?
>
>
>



 
Reply With Quote
 
Laurent Bugnion [MVP]
Guest
Posts: n/a
 
      5th Feb 2007
Nathan,

Nathan Sokalski wrote:
> When AJAX makes a call and recieves a response, the response is not the
> sending of a Response object, it is a call to a JavaScript function on the
> page using AJAX. Cookies are set when the Response object is set because
> what causes a cookie to be set are headers in the HTTP. Because the Response
> object, which is what the other page is setting the headers in, does not get
> sent, you are never actually telling the browser to set the cookies. I will
> admit that I am not yet an expert in AJAX, but I think that this is if not
> the exact reason for your problem, it has something to do with the reason
> and should help you find it. Good Luck!


This is not correct. When you send a XmlHttpRequest using the Web
browser, the request sent is a perfectly normal request. The response to
that is a perfectly normal response. Granted, it will often contain XML
and not HTML, but HTTP responses can do that.

Cookies should be handled correctly in AJAX too.

To Mr. Sweaty Finger: You must make sure that the page setting the
cookies does this correctly. To do that, use Fiddler to watch the HTTP
traffic between your IE and the web server. This will help you find out
if the cookies are not set correctly, or if they are set correctly but
incorrectly received.

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft-LB.ch
PhotoAlbum: http://www.galasoft-LB.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
 
Reply With Quote
 
George Ter-Saakov
Guest
Posts: n/a
 
      5th Feb 2007
Browser and Ajax call share cookie container. So if you are setting cookies
in a Ajax return it should work.
The only reason I think it might now work if you are making Ajax call to
another server.

Meaning that your page was served from www.mysite.com and you are making
Ajax call to www.anothersite.com
PS: www.mysite.com and site.com will be 2 different sites. URL must match
exactly (not case sensitive though).


George.


"Mr. SweatyFinger" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> OK I don't understand ajax, but my page makes a quick ajax call to another
> page and returns the results.
> that works ok.
>
> That other page is supposed to set a cookie.
>
> That doesn't seem to work.
>
> Is that because ajax doesn't send all the headers and cookies, or am i
> being a big dumb jerk?
>
>
>



 
Reply With Quote
 
Mr. SweatyFinger
Guest
Posts: n/a
 
      5th Feb 2007
The answer is that the cookies expired immediately because i did not set an
expiration date

Since they expired they appeared to not have been set.

So yes, they did get transferred via the ajax

oops

thanks everyone


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Give Request.Cookies and Response.Cookies is there any reason to use another method to use cookies? _Who Microsoft ASP .NET 7 18th Sep 2008 08:49 PM
ASP.NET AJAX samples... I am looking for help with HoverMenu AJAX Toolbox control. JDeats Microsoft ASP .NET 1 5th Oct 2007 08:50 PM
Ajax en the Form_load event and Ajax in serveruser controls =?Utf-8?B?VG9u?= Microsoft ASP .NET 2 22nd Jun 2007 10:16 AM
ASP.NET AJAX Enabled Website Web.config error (newbie to AJAX) Tony K Microsoft ASP .NET 2 4th May 2007 05:23 AM
Deploying ASP.NET AJAX-Enabled Web site to host without AJAX insta =?Utf-8?B?QnJpYW4gRWR3YXJkcw==?= Microsoft ASP .NET 2 21st Feb 2007 10:22 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:58 AM.