jquery - How to add a callback to a function in javascript -


i have 2 javascript functions

function 1 () {    long... writing jpgfile on disk }  function 2 () {    fast... show file } 

i call (in jquery) this

 1 ();  2 (); 

because function 2 needs link file function one, need sure execution completed... getting function 2 in callback of function 1 should trick.. how ?

note : did put alert ('aaa') between 2 functions let function 1 complete, , worked fine... when alert commented (removed) nothing works anymore !

you need use callback if doing asynchronous, otherwise doesn't matter how long takes, next function won't run until first has finished.

a callback passing function argument, , calling when done.

function 1 (callback) {    long... writing jpgfile on disk    callback(); }  function 2 () {    fast... show file }  one(two); 

obviously, if are doing asynchronous, need tell when finished (such event firing).


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -