Deki
Posts: 0
Joined: Tue Apr 15, 2014 4:53 pm

localStorage value is not updated with latest value on Load

I have the following code below. I want to first execute a query which writes to a localStorage variable. Then I want to retrieve that value from the localStorage variable. However, the problem is that the localStorage variable that gets evaluated at the time the code runs is a previous localStorage value. It does not update first, as the code has the query to run first before it retrieves a localStorage variable.

pre
var value = localStorage.getItem('dimensions');
var obj = jQuery.parseJSON(value);
....do other stuff with obj
/pre

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

localStorage value is not updated with latest value on Load

Hi Deki,

[quote:]I want to first execute a query which writes to a localStorage variable[/quote]Could you please clarify if you fill localSorage with REST service results? Then you can run your code on service Success event.

Deki
Posts: 0
Joined: Tue Apr 15, 2014 4:53 pm

localStorage value is not updated with latest value on Load

Yes, the code is actually like this. So, the query service runs and fills the localStorage variable (in the Result). Then I try to extract the localStorage, but it always gives me the previous value (from a previous test) and not the current one.

pre
query_srv.execute();
var value = localStorage.getItem('dimensions');
var obj = jQuery.parseJSON(value);
....do other stuff with obj
/pre

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

localStorage value is not updated with latest value on Load

Hi Deki,

This is because the service is executed asynchronously.

You would need to add the code that uses service response to service Success event.

Please find how to do it with JS here:
http://api.jquery.com/jQuery.ajax/

Here is how to do it within Appery.io:
http://devcenter.appery.io/documentat...

Return to “Issues”