473,388 Members | 1,326 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,388 software developers and data experts.

ajax and cookies

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?

Feb 5 '07 #1
4 6139
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
nj********@hotmail.com
http://www.nathansokalski.com/

"Mr. SweatyFinger" <sw@sw1finger.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
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?

Feb 5 '07 #2
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
Feb 5 '07 #3
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" <sw@sw1finger.comwrote in message
news:%2****************@TK2MSFTNGP06.phx.gbl...
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?

Feb 5 '07 #4
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
Feb 5 '07 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

24
by: Larry | last post by:
Hi there: I have seen numerous postings about eval() and its evils on this forum. However, one of our developers is using it in the following way, which seems like a great use of it. Page...
1
by: zyon2k | last post by:
Hi, i'm new to ajax and javascript. i would like to login in a webapp and to keep the session until i logout. The webapp is developed in asp and return a cookie after login. I'm already...
5
by: Ruso | last post by:
I am using ASP to make an application. What I want right now - is to make the self updating list of the users online - based on thier cookies. In my opinion all seems to be writen well with it's...
1
by: Aquaren | last post by:
I have a framework that uses the front controller design pattern for a single point of entry to the application and the autoload function for includes. I am trying to incorporate AJAX into the...
9
by: dougloj | last post by:
Hi. I have an ASP.NET application written in C#. In part of my application, I want to use JavaScript OnClick event function to update a textbox with a string generated asynchronously on the...
3
by: Beshoo | last post by:
hey gaiz plz I want to cerate log in system in ajax i do it but i have one problem AFTER I start thes session then press refresh key the session gone !!! in other words , after the user type hid...
5
by: pbd22 | last post by:
Hi. I am having a hard time figuring this one out... I have a sign in page. in my sign in logic, the successful login uses forms authentication and assigns an HttpCookie for the site-wide...
10
by: bhappy | last post by:
Hai All, im facing different problem with ajax. Im using ajax code for country,state & city dropdownlists. In city dropdownlist i had an option to add new city.Im selecting other option in city...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.