Click here to Skip to main content
15,879,326 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends I have four function in jQuery. I need to call this function one after another ie 2nd function should be worked only after 1st function complete.
how can i call this function without affecting the site performance.

$.fn.loadcombo_Name
$.fn.loadcombo_Head
$.fn.loadcombo_Bank
$.fn.loadcombo_Remarks

any help will be appreciated
Posted
Comments
Mukesh Pr@sad 13-Oct-14 1:40am    
You can use below code.

$.when( fn.loadcombo_Name() ).done(function() {
fn.loadcombo_Head();
});

for more please go to:-
http://api.jquery.com/jquery.when/

Hope..! it will help you.

May be you can return a value(true/false) from each function and based on the returned value call the next function in the row.
Hope this helps.
Thanks:)
 
Share this answer
 
 
Share this answer
 
Javascript is always synchronous and single-threaded meaning if you're executing a Javascript block of code on a page then no other Javascript on that page will currently be executed. Synchronous means after one function is complete only the other will load.
Synchronous calls Fiddle[^]
Javascript is only asynchronous in the sense that it can make, for example, AJAX calls. The code will stop executing until the call returns (successfully or in error), at which point the callback will run synchronously. No other code will be running at this point. It won't interrupt any other code that's running.

Thus you can always, perform synchronous operations for calling javascript functions unless u make an ajax request.
Thanks
:)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900