javascript - Why function in a loop is working only once? -


i'm working on progressbar google app script , jquery. when click on submit, following code run:

    var i=0;     while (i<100){       var prog=google.script.run.counttime();       i+=prog;       button.progressincrement(i);     } 

the progressbar feeded @ 10% , execution stopped.

the counttime() function not important (only returns 10 moment):

function counttime(){    return 10; } 

but if remove function, works (100%):

 while (i<100){     var prog=10;     i+=prog;     button.progressincrement(i);  } 

if remove loop , write this:

    var i=0;     var prog=google.script.run.counttime();     i+=prog;     button.progressincrement(i);     var prog=google.script.run.counttime();     i+=prog;     button.progressincrement(i);     var prog=google.script.run.counttime();     i+=prog;     button.progressincrement(i);     var prog=google.script.run.counttime();     i+=prog;     button.progressincrement(i);     var prog=google.script.run.counttime();     i+=prog;     button.progressincrement(i);     (....) 

the progressbar works 100% too.

what wrong function inside while?

google.script.run() doesn't return value, runs asynchronously. pass callback function value via withsuccesshandler(). example in client side code:

function onsuccess(valuefromserver) {      // valuefromserver }  google.script.run.withsuccesshandler(onsuccess).dosomethingserverside() 

and server side:

function dosomethingserverside() {     return valuefromserver } 

Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -