0

I have two functions. I'd like moduleList() to load AFTER reloadModules():

reloadModules();
moduleList();

function reloadModules() {
    $.get(v2_settings_url + 'v2_nav/', null, function(responseText) {
        $('#dock ul').html(responseText).parent().fadeIn();
    });
    $.get(v2_settings_url + 'v2_edit_bar_nav/', null, function(responseText) {
        var target = $('#edit-nav-bar-settings-div');
        target.html(responseText);
    });
};

2 Answers 2

4

Then simply pass the moduleList(); function as a callback function (a parameter) to the reloadModules(); function. Then chain your ajax calls and the moduleList(); function this way:

reloadModules(moduleList);

function reloadModules(moduleList) {
    $.get(v2_settings_url + 'v2_nav/', null, function(responseText) {
        $('#dock ul').html(responseText).parent().fadeIn();
        $.get(v2_settings_url + 'v2_edit_bar_nav/', null, function(responseText){
            var target = $('#edit-nav-bar-settings-div');
            target.html(responseText);
            moduleList();
        });
    });
};

Now, in simple words, you're telling the browser to:

  1. Execute reloadModules function, while passing it the moduleList function.
  2. Get something from server
  3. If you got it successfully, get something else from server
  4. If you got it successfully, run the moduleList function
Sign up to request clarification or add additional context in comments.

Comments

1

call moduleList(); at the end of reloadModules(); and call reloadModules() where you want to call both ! Hope this helps.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.