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

  • SEARCH
  • Home
  • 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 8981083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T20:14:43+00:00 2026-06-15T20:14:43+00:00

Need to wait for several requests to facebook to complete before taking a final

  • 0

Need to wait for several requests to facebook to complete before taking a final action on the page (updating the count of how many requests returned info) but not sure how to approach it.

How do you check that each function is complete and update a counter before firing a function.
window.load is too early unless the page is refreshed after login…?

    window.fbAsyncInit = function () {
     FB.init({
     appId: 'id', // App ID
     //channelUrl: '//facebookdev.smithbrosagency.com/LOL/xss_channel.htm', // Channel File
     status: true, // check login status
     cookie: true, // enable cookies to allow the server to access the session
     xfbml: true  // parse XFBML
     });

     getStatus();

      //Subscribe to events
     FB.Event.subscribe('auth.statusChange', function (response) { if (response.authResponse) { getStatus(); } });
     FB.Event.subscribe('auth.login', function (response) { if (response.status === 'connected') { getStatus(); } });
    };
     function getStatus() {
      FB.getLoginStatus(function (response) {

      if (response.status === 'connected') {
       setPanel('results'); // connected

       var accessToken = response.authResponse.accessToken;

       var obj = getPermissionsObject(function (permissions) {

       getUserInfo(response);

       getUserPhotos(response, accessToken);

       getFriends(response, accessToken);

       getUserLocations(response, accessToken);

       getUserMusic(response, accessToken);

       getUserMovies(response, accessToken);

           });
      } else {
       setPanel('login'); // not logged in or unauthorized
      }
      });
     }
     function getUserPhotos(response, accessToken) {

      FB.api('/me/photos?access_token=' + accessToken, function (response) {
      var photoList = response.data;
      var len = photoList.length;
      if (len >= 3) {

       var max = 3;
   if (len > max) { len = max }; // cap it at 3

   for (var i = 0; i < len; i++) {
   (function () {
    var j = i;
    var idx = i + 1;
    $('.result2 .option' + idx + ' input').val(photoList[i].picture);
    $('.result2 .option' + idx + ' img').attr("src", photoList[i].picture);

       })();
    }
       $('div.result2').addClass("active");
       $('#q2 input').val(1); // add to hidden to count results
          }
    else {
       // hide & subtract from total questions
       $('div.result2').addClass("inactive");
       $('#q2 input').val(0); 
      }
      });
     }

     $(window).load(function () {
      $.when($('#q2 input').val() != '' && $('#q4 input').val() != '' && $('#q5 input').val() != '').then(test());

      function test() {

      // calc total questions
      var total = 0;

      $("#Results div input[hidden]").each(function () {
       total += $(this).val() * 1;
      });
      alert(total);
      }
     });
  • 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-06-15T20:14:45+00:00Added an answer on June 15, 2026 at 8:14 pm

    I’m not sure if I understand you correctly but it seems you need to implement an object like this:

    <script type="text/javascript">
    
    //Monitoring object
    function RequestStatusMonitor()
    {
        this.resetRequests();
    }
    
    //IDs of the requests you need to monitor
    RequestStatusMonitor.prototype.requests=["firstRequest","secondRequest","thirdRequest"];
    
    //Status of the requests
    RequestStatusMonitor.prototype.requestsCompleted=[];
    
    //Set all requests to incomplete state
    RequestStatusMonitor.prototype.resetRequests = function()
    {
        this.requestsCompleted = [];
        for(var it in this.requests)
        {
            this.requestsCompleted[this.requests[it]] = false;
        }
    }
    //Set status for a request determined by requestName
    RequestStatusMonitor.prototype.setRequestStatus = function(requestName, status)
    {
        this.requestsCompleted[requestName] = status;
    }
    
    //Check if all requests are completed
    RequestStatusMonitor.prototype.allRequestsAreCompleted = function()
    {
        for(var it in this.requestsCompleted)
        {
            if(!this.requestsCompleted[it])
            {
                return false;
            }
        }
        return true;
    }
    
    //----------------------------------------------------------------------------------
    //Usage Example
    var monitor = new RequestStatusMonitor();
    
    function onFirstRequestFinished(/*necessary parameters*/)
    {
        monitor.setRequestStatus("firstRequest", true);
        checkCompleted();
    }
    
    function onSecondRequestFinished(/*necessary parameters*/)
    {
        monitor.setRequestStatus("secondRequest", true);
        checkCompleted();
    }
    
    function onThirdRequestFinished(/*necessary parameters*/)
    {
        monitor.setRequestStatus("thirdRequest", true);
        checkCompleted();
    }
    
    function checkCompleted()
    {
        if(monitor.allRequestsAreCompleted())
        {
            //Do what you need after all requests are completed
            alert("All requests are completed");
        }
    }
    
    onFirstRequestFinished();
    onThirdRequestFinished();
    onSecondRequestFinished();
    
    </script>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my problem: I need to do several requests on a server. These
I need to generate requests to several APIs, get response from them and then
I am doing a media file scan using sendBroadcast. Then I need to wait
I need a way to wait until a (Swing) JComponent is fully painted. This
I need files to be downloaded to /tmp/cron_test/. My wget code is wget --random-wait
I need to run two ffmpeg commands, one after the other i.e., wait until
I have a php script I need to run every 5 seconds (run, wait
Using Mechanize, I need to find some way to limit requests to 1 per
I have a web application running on Tomcat. There are several calculations that need
I need to parse several large size XML files (one is ~8GB, others are

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.