Page 1 of 1

localstorage data is getting delay from services

Posted: Wed Apr 16, 2014 4:04 am
by deveu

service1--------localstorgae (total_item)
service2--------localstorgae (total_point)

those services i execute on page show

now i have js script on page show to get data from those localstorgae
soemtime data is showing null
if i put an alert at my starting script being delay and data is getting properly
how may i fix this

Why localstorage data is previous data/null

available_points = localStorage.getItem("local_available_points");
total_items = localStorage.getItem("local_total_items");

for (i = 0; i < total_items; i++) {

Code: Select all

 required_points = parseInt($('#Reward_reward_grid_' + i).find("#Reward_required_points").val()); 
 btn_reward = $('#Reward_reward_grid_' + i).find("#Reward_btn_reward"); 

// alert(available_points+" "+total_items+" "+required_points); 
 if (available_points = required_points) { 
     btn_reward.css('background-color', '#BFD770'); 
     btn_reward.attr("style", "width:150px;height:50px;background-color:#BFD770;border-radius:25px !important"); 
 } else { 
     reward_more = parseInt(required_points) - parseInt(available_points); 
     reward_more = reward_more + " more check-in"; 
     btn_reward.text(reward_more); 
     btn_reward.css('background-color', '#B5B4B5'); 
     btn_reward.attr("style", "width:150px;height:50px;background-color:#B5B4B5;border-radius:25px  !important"); 
     btn_reward.attr("disabled", "disabled"); 
 } 

}


localstorage data is getting delay from services

Posted: Wed Apr 16, 2014 4:44 am
by Alena Prykhodko

Hi Deveu,

You problem is in async services.

When you invoke the service, it takes some time.

Thus if you need data from these two services please follow these steps:

1 Create new JS and fill it with code below:
pre

function ProcessYourData(){

available_points = localStorage&#46;getItem("local_available_points");
total_items = localStorage&#46;getItem("local_total_items");

for (i = 0; i < total_items; i++) {

required_points = parseInt($('#Reward_reward_grid' + i)&#46;find("#Reward_required_points")&#46;val());
btn_reward = $('#Reward_reward_grid' + i)&#46;find("#Reward_btn_reward");

&#47;&#47; alert(available_points+" "+total_items+" "+required_points);
if (available_points = required_points) {
btn_reward&#46;css('background-color', '#BFD770');
btn_reward&#46;attr("style", "width:150px;height:50px;background-color:#BFD770;border-radius:25px !important");
} else {
reward_more = parseInt(required_points) - parseInt(available_points);
reward_more = reward_more + " more check-in";
btn_reward&#46;text(reward_more);
btn_reward&#46;css('background-color', '#B5B4B5');
btn_reward&#46;attr("style", "width:150px;height:50px;background-color:#B5B4B5;border-radius:25px !important");
btn_reward&#46;attr("disabled", "disabled");
}
}

}/pre

2 Add to the service1 "success" JS event handler. And fill it with code:
pre

if(localStorage&#46;getItem("local_available_points"));
ProcessYourData();/pre

3 Add to the service2 "success" JS event handler. And fill it with code:

pre
if(localStorage&#46;getItem("local_total_items"));
ProcessYourData();/pre

4 Delete your code on "page show" js event handler.


localstorage data is getting delay from services

Posted: Wed Apr 16, 2014 7:04 am
by deveu

if(localStorage.getItem("local_available_points"));
ProcessYourData();

why semiclone

i think that will be

if(localStorage.getItem("local_available_points"))
{
ProcessYourData();
}

right?


localstorage data is getting delay from services

Posted: Wed Apr 16, 2014 7:05 am
by deveu

2 times that is being call
but i need 1 time


localstorage data is getting delay from services

Posted: Wed Apr 16, 2014 7:38 am
by deveu

if(localStorage.getItem("local_available_points")&&localStorage.getItem("local_total_items"))
{
ProcessYourData();
}

I set this both places
let me check more and I will inform you again


localstorage data is getting delay from services

Posted: Wed Apr 16, 2014 8:03 am
by Kateryna Grynko

Hi Deveu,

Will wait for your update.


localstorage data is getting delay from services

Posted: Wed Apr 16, 2014 8:12 am
by deveu

I am getting 2 time data by aleart
1 is with previous data and another is new data

I added those function in success

I did this on 2 events on success

if(localStorage.getItem("local_available_points")&&localStorage.getItem("local_total_items"))
{
ProcessYourData();
}

common function in main js

function ProcessYourData() {
available_points = localStorage.getItem("local_available_points");
total_items = localStorage.getItem("local_total_items");
for (i = 0; i < total_items; i++) {
required_points = parseInt($('#Reward_reward_grid' + i).find("#Reward_required_points").val());
btn_reward = $('#Reward_reward_grid' + i).find("#Reward_btn_reward");
alert("available_points:"+available_points+" required_points:"+required_points);
if (available_points = required_points) {
btn_reward.css('background-color', '#BFD770');
btn_reward.attr("style", "width:150px;height:50px;background-color:#BFD770;border-radius:25px !important");
} else {
reward_more = parseInt(required_points) - parseInt(available_points);
reward_more = reward_more + " more check-in";
btn_reward.text(reward_more);
btn_reward.css('background-color', '#B5B4B5');
btn_reward.attr("style", "width:150px;height:50px;background-color:#B5B4B5;border-radius:25px !important");
btn_reward.attr("disabled", "disabled");
}
}
}


localstorage data is getting delay from services

Posted: Wed Apr 16, 2014 8:13 am
by deveu

my pages are repeated for various customer


localstorage data is getting delay from services

Posted: Wed Apr 16, 2014 8:50 am
by deveu

but I cant not understand
getting success with previous data and why

i fix this by resting localstorage to 0 and checking on in function


localstorage data is getting delay from services

Posted: Wed Apr 16, 2014 3:29 pm
by Maryna Brodina

Hello!

I'm sorry, not sure I understand... Could you clarify your question please?