Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Retain Javascript objects across postbacks

Tags:

javascript

I use to append according to data array in table on button click, but when I click other button due to postback all the created structure goes away, is there any way that I can retain that structure inspite of postback?

Thanx

like image 960
BreakHead Avatar asked Apr 12 '26 07:04

BreakHead


2 Answers

When you redirect to another page all values that were stored in javascript variables are garbage collected and are no longer available. There are different techniques allowing you to persist values on the client side. One is using cookies. Another is using HTML5 local storage.

like image 58
Darin Dimitrov Avatar answered Apr 14 '26 19:04

Darin Dimitrov


No. Making a post request leaves the current page, and the current page is the execution environment.

You'll need to include all the data you need to reconstruct the state in the submitted data and then rebuild it on the other side.

like image 31
Quentin Avatar answered Apr 14 '26 20:04

Quentin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!