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
Post a Comment