Login or Sign up Help | Site Map
Connecting Tech Pros Worldwide

session handling in javascript

Question posted by: vijay0456 (Newbie) on August 17th, 2007 12:50 PM
Hi everyone,
I wanted to know weather we can handle session using javascript.
Simply if i can test weather session is valid or not(i.e expired or still existing) does my work.
I was trying for it from past a week if anyone could help i would be happy.

Thanks and Regards,
Vidya Sagar Reddy.
Would you like to answer this question?
Sign up for a free account, or Login (if you're already a member).
kestrel's Avatar
kestrel
Moderator
900 Posts
August 17th, 2007
12:52 PM
#2

Re: session handling in javascript
Im going to move this to the Javascript Fourm. Have a nice day!

--
Kestrel

Reply
vijay0456's Avatar
vijay0456
Newbie
5 Posts
August 17th, 2007
12:54 PM
#3

Re: session handling in javascript
Thanks and sorry i have posted at a wrong place

Reply
kestrel's Avatar
kestrel
Moderator
900 Posts
August 17th, 2007
01:00 PM
#4

Re: session handling in javascript
Dont worry too much about it. I get them all day long.

Reply
epots9's Avatar
epots9
Moderator
1,303 Posts
August 17th, 2007
01:20 PM
#5

Re: session handling in javascript
Quote:
Originally Posted by vijay0456
Hi everyone,
I wanted to know weather we can handle session using javascript.
Simply if i can test weather session is valid or not(i.e expired or still existing) does my work.
I was trying for it from past a week if anyone could help i would be happy.

Thanks and Regards,
Vidya Sagar Reddy.


javascript doesn't do sessions, it does cookies.

well....if u use ajax then you can create session variables (using php, asp.net,...).

good luck

Reply
vijay0456's Avatar
vijay0456
Newbie
5 Posts
August 17th, 2007
01:28 PM
#6

Re: session handling in javascript
Quote:
Originally Posted by epots9
javascript doesn't do sessions, it does cookies.

well....if u use ajax then you can create session variables (using php, asp.net,...).

good luck

@epots9

Thanks a lot buddy
I have done an example using ajax but for a big web page if we use ajax call for every hit is a costly work i think so i am trying for an alternative and less costlier. Can u suggest any alternative.

I am using only one page and in the same page i am playing with the javascript (like say hide and seek) but the session is only this which should be taken care .

Reply
epots9's Avatar
epots9
Moderator
1,303 Posts
August 17th, 2007
01:33 PM
#7

Re: session handling in javascript
then just create cookies with javascript, i guess when the page loads make sure that the cookie(s) is(are) valid. cookies and sessions are pretty much the same, cookies are stored client-side and sessions are stored server-side.

Reply
ahoyer's Avatar
ahoyer
Newbie
14 Posts
August 17th, 2007
03:01 PM
#8

Re: session handling in javascript
Quote:
Originally Posted by epots9
well....if u use ajax then you can create session variables (using php, asp.net,...).


would you be able to give an example of how i would use ajax to set an asp.net session variable?

Reply
epots9's Avatar
epots9
Moderator
1,303 Posts
August 17th, 2007
03:15 PM
#9

Re: session handling in javascript
Quote:
Originally Posted by ahoyer
would you be able to give an example of how i would use ajax to set an asp.net session variable?


in your asp.net page just create a session variable as u normally would

Reply
ahoyer's Avatar
ahoyer
Newbie
14 Posts
August 17th, 2007
03:32 PM
#10

Re: session handling in javascript
Quote:
Originally Posted by epots9
in your asp.net page just create a session variable as u normally would


Sorry, i should have been a little more specific, i know that in my asp.net behind code (say c#) i would just go like this in a method:

Code: ( text )
  1. Session["varName"] = "some value";


what i was then wondering is how i could then use ajax or something in someway to call this from a javascript function. (i honestly dont know if this is possible, im pretty new to web dev, and i know little - nothing about ajax).

The reason why i wonder, is ive got an asp button, that when clicked i would like it to set the session variables, then open a new window (using javascript, window.open()) that will use those same session variables in some way.

Reply
epots9's Avatar
epots9
Moderator
1,303 Posts
August 17th, 2007
03:54 PM
#11

Re: session handling in javascript
the javascript doesn't get it directly. in your asp.net page u do all validation of the session there, then if its valid or not the page returns true or false (return statement is added by the programmer, you, and it returns whatever u tell it). then back in the javascript it will receive the true or false and based on that do whatever it is you wanted it to do, it will do that.

Reply
Reply
Not the answer you were looking for? Post your question . . .
184,212 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
Top Javascript / DHTML / Ajax Forum Contributors