Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript variable scoping - persisting state?

I have the following setup, and I need to know how to persist state.

1.) An external web page uses ajax to load and display a .jsp file, which contains javascript. 2.) Once this rendering is complete, javascript in the .jsp file must be called to perform an action based on the results that occurred during rendering. Specifically, the document does action on $(document).ready, and those actions dictate what must be done on later function calls.

The question I have is this: How do I persist the data and state created when the page is loaded? I tried something like this:

External: ajax to test.jsp

Internal test.jsp

var saveMe = {};

function getsCalled()  
{  
    saveMe = {'a':function(){return false;}};  
}  

function needsData()  
{  
    //???  
}  

Later...
External:

needsData();  

Nothing I seem to attempt is working. What would be the best way to persist state in this situation?

like image 295
Stefan Kendall Avatar asked Nov 27 '25 17:11

Stefan Kendall


1 Answers

If you want to know about scoping read this. It might help you to work out what is going on.

like image 57
Mark Dickinson Avatar answered Nov 29 '25 06:11

Mark Dickinson



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!