You need to make sure that the destination can be accessible outside the scope of the outgoing call.
If getstate not declared outside the request for receipt, it will not be available for subsequent calls.
Question: when or in what area do you need this data?
You can simply place it under the window area. Although it is bad practice to put everything under the global scope, it will give you an idea of ββwhere to put it.
console.log('data is' + data); window.getstate = data;
Now, at any time after its appointment, it will be available through window.getstate or just getstate .
source share