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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T13:19:49+00:00 2026-06-04T13:19:49+00:00

I have a DIV in this data is loaded from the server. I want

  • 0

I have a DIV in this data is loaded from the server. I want my JS to execute now only when there is data in the Div. Data is being loaded by Facebook’s API

<Div id='profilePicsDiv' > DATA</div>

JS

$(document).ready(function () {

    FB.getLoginStatus(function (response) {
        var profilePicsDiv = document.getElementById('profile_pics');
        FB.api({
            method: 'friends.get'
        }, function (result) {

            // var result =resultF.data;
            // console.log(result);
            var user_ids = "";
            var totalFriends = result.length;
            // console.log(totalFriends);
            var numFriends = result ? Math.min(25, result.length) : 0;
            // console.log(numFriends);
            if (numFriends > 0) {
                for (var i = 0; i < numFriends; i++) {
                    var randNo = Math.floor(Math.random() * (totalFriends + 1))
                    user_ids += (',' + result[randNo]);
                    randNo++;
                    if (randNo >= totalFriends) {
                        randNo = 0;
                    }
                    // console.log(user_ids);
                }
            }
            profilePicsDiv.innerHTML = user_ids;
        });
    });

}

Now i want after the data is loaded to execute this

$(document).ready(function () {
    var user_ids = document.getElementById('profile_pics').innerHTML;

    if (user_ids == '') {} else

    {
        FB.ui({
            method: 'apprequests',
            message: 'See anyones secret hidden pictures :)',
            to: user_ids,
            ///  How to Fill the ID's HERE ?
        }, requestCallback);
    }
}

function requestCallback(response) {
    // Handle callback here
}

});

But 80% I get the Alert as Blank and 20 % time i get values , Can i do something that this function is executed after its sure to have the data and avoide the 80% chance that its Blank?

  • 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-04T13:19:50+00:00Added an answer on June 4, 2026 at 1:19 pm

    Facebook Api does ajax request to fetch results. So, this approach wont help.

    Even when window is loaded completely, facebook data wont be there always ( it takes time to request ajax and get the result back from facebook server)

    Also, as @jmort253 pointed,

    Using window.onload in combination with document.ready is
    redundant.Get rid of window.onload and stick to jQuery

    Do your logic on facebook api callbacks only.

    e.g.

    FB.api('/me/friends?fields=name,first_name,gender,picture,relationship_status,birthday', function(response) {
            // Do your logic here
    
        })
    

    Edit

    You should do something like this,

    $(document).ready(function () {
       FB.getLoginStatus(function (response) {
        var profilePicsDiv = document.getElementById('profile_pics');
        FB.api({
            method: 'friends.get'
        }, function (result) {
    
            // var result =resultF.data;
            // console.log(result);
            var user_ids = "";
            var totalFriends = result.length;
            // console.log(totalFriends);
            var numFriends = result ? Math.min(25, result.length) : 0;
            // console.log(numFriends);
            if (numFriends > 0) {
                for (var i = 0; i < numFriends; i++) {
                    var randNo = Math.floor(Math.random() * (totalFriends + 1))
                    user_ids += (',' + result[randNo]);
                    randNo++;
                    if (randNo >= totalFriends) {
                        randNo = 0;
                    }
                    // console.log(user_ids);
                }
            }
            profilePicsDiv.innerHTML = user_ids;
             FB.ui({
            method: 'apprequests',
            message: 'See anyones secret hidden pictures :)',
            to: user_ids,
            ///  How to Fill the ID's HERE ?
           }, requestCallback);
    
        });
    });
    
    });
    function requestCallback(response) {
        // Handle callback here
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this jQuery script: $(.show-div).data('loaded',false).click(function() { $.post(script.php, {id_1: var_id_1, id_2: var_id_2}, function(data){ $(this).data('loaded',true);
I have this data: <div id=results> <span id=row> <span id=left>left column</span> <span id=middle>middle text</span>
I have some data like this <div> This is some text </div> and i
I have this as my html; <div data-role=page id=page1> <div data-role=content class=Content> <a href=#popupBasic
atm I have something like this: $('#fish').append(<div data-bind='foreach: rows'> + <div ... + <p>...</p>..);
I have a DataGrid that is loaded from an XML data store, all created
I want to add Loaded html from Ajax request to Div with effect (for
Hi i have a div as like that This is Frame a div This
I have this div and inside the div is an image, and what I
I have this div as part of an include fine: .connier { text-align: left;

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.