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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T17:19:07+00:00 2026-06-15T17:19:07+00:00

I have 3 json requests which fetch data, i am wanting to store the

  • 0

I have 3 json requests which fetch data, i am wanting to store the results and add them together? i have made an attempt but i get NaN as they are getting set as null. What am i doing wrong?

var twitter, facebook, web, total_count;

    // grab from facebook
    var facebook = $.getJSON('https://graph.facebook.com/'+f_page+'?callback=?', function(data) {
        var fb_count = data['likes'].toString();
        fb_count = add_commas(fb_count);
        $('#fb_count').html(fb_count);
    });

    // grab from twitter
    var twitter = $.getJSON('http://api.twitter.com/1/users/show.json?screen_name='+t_page+'&callback=?', function(data) {
        twit_count = data['followers_count'].toString();
        twit_count = add_commas(twit_count);
        $('#twitter_count').html(twit_count);
    });

    // grab from website
    var web = $.getJSON('json.php', function(data) {
        web_count = data['count'].toString();
        web_count = add_commas(web_count);
        $('#website_count').html(web_count);
    });

    $.when(facebook, twitter, web).done( countTotal );

    function countTotal() {
        total_count = facebook + twitter + web;
        total_count = add_commas(total_count);
        $('#count_total').html(total_count);
    }
  • 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-15T17:19:08+00:00Added an answer on June 15, 2026 at 5:19 pm

    You are trying to acces data that is asychronously loaded. That means when the program code comes to this line:

    total_count = fb_count + twit_count + web_count;
    

    The data isn’t there yet.

    You need to wait until the data is ready:

    var fb_count, twit_count, web_count, total_count;
    
    var first = $.getJSON( /* code1 */);
    var second = $.getJSON( /* code2 */);
    var third = $.getJSON( /* code3 */);
    
    $.when(first, second, third).done( doYourMath );
    
    function doYourMath() {
        total_count = fb_count + twit_count + web_count;
        total_count = add_commas(total_count);
        $('#count_total').html(total_count);
    }
    

    PS:
    Make sure total_count is defined somewhere as variable (var total_count), else it will pollute the global scope.

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

Sidebar

Related Questions

I have a method which requests external webservices and returns json here: public string
I have a site, which requests data from a SQL DB, from different rows,
I have a script which uses ajax(json) to fetch Google suggestions(xml), demo: JsFiddle I
I have made an json api for a database which has some products, and
I have a data Store that gets it's information from a JSON api on
I have a php function which returns JSON in response to a ajax request
i have json data like this {GetStudentDetails: {TotalCount:5, RootResults:[ {city:West Chester,country:USA,state:PA ,student_id:100}, {city:Philly,country:USA,state:PA,student_id:101}, {city:Buffalo,country:USA,state:NY,student_id:102},
I have a JSON request, but it seems that it is not hitting the
I have an application in which most requests are submitted via AJAX, though some
I have data on a server which stores name and images. I want to

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.