JavaScript CookBook/AJAX Interactions/Chaining multiple AJAX-based functions

From GeoMedia Smart Client
Jump to: navigation, search
GMSC 2013/2014 Javascript API Overview Form Events Types Utility Functions client-side Validation Conditions Interaction with SmartClient Cookbook Cheatsheet


Chaining multiple AJAX-based functions

Problem: You want to chain multiple AJAX-based functions together so that the second function starts after the AJAX request of the first function finished.

Solution: By nesting the callbacks of the two functions you can maintain the sequential execution order:

 IG.getItemById('DATACONNECT').reload().done(function (data) {
     //IG.trigger is called in the done callback of the field reload
     //so it is executed after DATACONNECT was reloaded
     IG.trigger({triggerNames:['TriggerAssignPluginParam']}).done(function (result) {
        //reload the feature after executing the trigger
         IG.reloadFeature('1');
     })
 })

Note: .reload() and IG.trigger() both return a jQuery AJAX object that allows the subscription of callbacks at any time. Please see the jQuery documentation for more details on using this object.


Other Recipes in this category: