what happens to javascript variable after a call to the server?
I just began to learn javascript, so 开发者_StackOverflow中文版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?
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.
It depends, what scope the variable is in. Also, Ajax is different then submitting a page, so your variables are persisted.
精彩评论