Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 4586560
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T21:39:21+00:00 2026-05-21T21:39:21+00:00

$(document).ready(function() { $(#list1).jqGrid({ url: ‘example1.php’, /*balabala…*/ gridComplete: function() { } }); $(#list2).jqGrid({ url: ‘example2.php’,

  • 0
$(document).ready(function() {
    $("#list1").jqGrid({
        url: 'example1.php',
        /*balabala...*/
        gridComplete: function() {

        }
    });

    $("#list2").jqGrid({
        url: 'example2.php',
        /*balabala...*/
        gridComplete: function() {

        }
    });

    /*I want to do something here, but the above grids must be both complete first.*/
    Something...
});

How should I do ? Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-21T21:39:22+00:00Added an answer on May 21, 2026 at 9:39 pm

    The easiest way is to put your “something” in the gridComplete callbacks but have the two callbacks check that the other one has finished. Something along these lines:

    function do_something_wonderful() {
        // This is the awesome stuff that you want to
        // execute when both lists have loaded and finished.
        // ...
    }
    
    var one_done = false;
    function done_checker() {
        if(one_done) {
            // The other one is done so we can get on with it.
            do_something_wonderful();
        }
        one_done = true;
    }
    
    $("#list1").jqGrid({
        //blah blah blah
        gridComplete: done_checker
    });
    $("#list2").jqGrid({
        //blah blah blah
        gridComplete: done_checker
    });
    

    This nicely extends to more than two lists with a couple small modifications:

    • use var how_many_done = 0; instead of one_done.
    • Do a ++how_many_done; instead of one_done = true; and move it to the top of done_checker.
    • Replace the if(one_done) with if(how_many_done == number_of_tasks) where number_of_tasks is how many AJAX tasks you have.

    The general version would look sort of like this:

    var number_of_tasks = 11; // Or how many you really have.
    var how_many_done   = 0;
    function done_checker() {
        ++how_many_done;
        if(how_many_done == number_of_tasks) {
            // All the AJAX tasks have finished so we can get on with it.
            do_something_wonderful();
        }
    }
    

    An even better version would wrap up the state in a closure:

    var done_checker = (function(number_of_tasks, run_when_all_done) {
        var how_many_done = 0;
        return function() {
            ++how_many_done;
            if(how_many_done == number_of_tasks) {
                // All the AJAX tasks have finished so we can get on with it.
                run_when_all_done();
            }
        }
    })(do_something_wonderful, 11);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following code: <script type=text/javascript> $(document).ready(function() { $(#Save).click(function() { $.post(url, { data:
$(document).ready(function() { $(span.link).mouseover(function(e){ $(this.children).css(display,inline); }); }); I'm not a javascript expert, but I've cobbled
$(document).ready(function(){ $(.txtDate).datepicker({ showOn: both, buttonImage: library/ui/datepicker/img/calendar2.gif, dateFormat: yy/mm/dd, buttonImageOnly: true }); //added this checkbox
Jquery has a great language construct that looks like this: $(document).ready(function() { $(a).click(function() {
Does anybody know why the following code only has effect in FF? $(document).ready(function() {
I have using the following code for developing tabs. $(document).ready(function() { $('#container-1').tabs(); } ....
I want to do this, but haven't figured it quite out yet... $(document).ready(function() {
I have created a function outside of $(document).ready() , but am still using jQuery
I would like to execute the jQuery $(document).ready() in a drupal site. While i
I read the SDK document, but can not understand some details, need some help.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.