views:

44

answers:

2

I just began to learn javascript, so here is a silly question :

What happens to a javascript variable after a call to the server? Are all the variables wiped out?

I read somewhere that javascript variable in ajax can act like session or cookie. Is that true?

A: 

It depends, what scope the variable is in. Also, Ajax is different then submitting a page, so your variables are persisted.

stevebot
A: 

All of the run-time state is reset whenever the browser does a page-load, such as navigating from foo.com/bar to foo.com/baz. This includes all JavaScript variables, as well as the current DOM. However, asynchronous calls to the server, such as XHR, do not affect run-time state, and all JavaScript variables will stay.

If you'd like to preserve values between page-loads, you can use cookies or localStorage.

bcherry
thanks , that point the right direction
dannynjust