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 1051147
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T16:53:04+00:00 2026-05-16T16:53:04+00:00

This sounds like a weird title and probably not stated too well. But here’s

  • 0

This sounds like a weird title and probably not stated too well. But here’s the issue.

I’ve got this method being called:

function BindFacebookAlbumAndPhotoData() 
{
    GetAllFacebookAlbums(userID, accessToken, function(aAlbums) 
    {
        if (aAlbums === null || aAlbums === undefined) 
        {
            // TODO: Need to handle this
            return;
        }

        var defaultAlbumID = aAlbums[0].id;

        BindFacebookAlbumDropdownList(aAlbums, defaultAlbumID);

        BindFacebookThumbnails(userID, accessToken, defaultAlbumID, photosContainerDivID);

        SetSelectDefaultOption(defaultAlbumID);
    });
}

So here’s the GetAllFacebookAlbums Method:

function GetAllFacebookAlbums(userID, accessToken, callbackFunction)
{
    var aAlbums = [];
    var uri = "/" + userID + "/albums?access_token=" + accessToken;

    // this is an async call so code after this will fire at the same time
    FB.api(uri, function(response) 
    {
        // check for a valid response
        if (!response || response.error) 
        {
            callbackFunction(albums);
        }

        for (var i = 0, l = response.data.length; i < l; i++) 
        {
            //do whatever
        }
    });

    // wait for the FB.api call to run a bit before calling code below
    window.setTimeout(callbackFunction(aAlbums), 5000);
}

What’s happening is this line is being called before the setTimeout it seems:

var defaultAlbumID = aAlbums[0].id;

the whole reason I put that timeout in there is so I can wait for the FB.api call to finish. Then call the callback after I know I have data. So how in the world are those lines in my callback being called when I have definitely not seen a 5 second delay before that callback is called?

  • 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-16T16:53:05+00:00Added an answer on May 16, 2026 at 4:53 pm

    This line right here:

    window.setTimeout(callbackFunction(aAlbums), 5000);
    

    You’re calling the function right there in the setTimeout() call. Wrap it in another function:

    window.setTimeout(function() { callbackFunction(aAlbums); }, 5000);
    

    Now, that said, the whole setup doesn’t really make much sense. You’ve already got code sitting in a place that you know will be called as soon as the data is ready. That’s the code in the Facebook API callback you’ve got. Why not just call your “callbackFunction” from in there?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This probably sounds like a terrible idea at first glance, but here is my
This may sounds like a stupid question but can't find anything on google, probably
Sounds like a weird question, but say I have something like this: $.post( /myajax.php,
This may seem like a weird question but thought I would ask here before
This sounds like a really simple question, but I am new to PHP. If
This sounds like a problem many others have posted about, but there's a nuance
I know this sounds like a homework assignment, but it isn't. Lately I've been
I know this sounds like a dumb question but I need to ask this.
I apologise if any of this sounds like a broken record but I've trawled
This may sound like a very generic question but here it goes. I have

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.