javascript - Execute a method whenever some method has finished executing completely -
i've javascript method defined follows:
updtcrtedtpage = function() {primefaces.ab({source:'j_id_ev',formid:'j_id_es',process:'typenewlob_in lobidforedit j_id_ev',update:'createlobfullpagepanel',oncomplete:function(xhr,status,args){prepareforcrtedtfullpage();},params:arguments[0]});}
i want execute method (aftercomplete()) whenever method has finished executing. (this method initiates ajax request & appends received html data on dom). want aftercomplete() method executed whenever ajax response has been received.
i cannot directly like:
updtcrtedtpage(); aftercomplete();
as call aftercomplete() after ajax request initiated & not finished executing yet.
is there js/ jquery way ?
you pass aftercomplete
parameter function can call when ajax call complete. this...
updtcrtedtpage = function(callback) { primefaces.ab({ source:'j_id_ev', formid:'j_id_es', process:'typenewlob_in lobidforedit j_id_ev', update:'createlobfullpagepanel', oncomplete:function(xhr,status,args){ prepareforcrtedtfullpage(); callback(); }, params:arguments[0] }); } updtcrtedtpage(aftercomplete);
since can't modify updtcrtedtpage
, can modify prepareforcrtedtfullpage
i'd suggest using global variable determine callback function call when method complete...
updtcrtedtpagecallback = aftercomplete;
and in prepareforcrtedtfullpage
add last line...
updtcrtedtpagecallback();
the first method tidier, second suffice particular situation.
Comments
Post a Comment