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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T13:19:44+00:00 2026-06-14T13:19:44+00:00

I have a simple AJAX call that is querying the Twitter API to return

  • 0

I have a simple AJAX call that is querying the Twitter API to return the number of times a URL has been tweeted. I’m trying to set that return value along with similar AJAXs calls from other social networks. I’m then want to add all the values together to get a ‘sharing’ total that will be used within HTML Page.

Here was what I was trying with my code:

var twitter = $.ajax({
        dataType: 'jsonp',
        url: 'http://cdn.api.twitter.com/1/urls/count.json',
        data: { url: shareUrl},
        async: 'false',
        success: function(data) {
            return data.count;
        }
    });

My goal is in then run a simple math function like this:

var total = twitter + facebook;

And then output that total to a DOM element.

When I run a console.log(twitter); I’m getting an object readystate but if I run a console.log of the count in the success function, I’m getting the correct number. Since this is going to be a very light page set ‘async: false’ hoping that it would return the value then move on to the next function. But not matter what I try and I can’t get the value out of the AJAX function. Where have I gone wrong or what do I need to modify?

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

    This is a perfect example for using deferreds in jQuery. With deferreds you can create callbacks that will be called after a series of asynchronous actions finished (and not only one as for usual callbacks).

    Then you can calculate the total of the results coming from the “inner” callbacks

    EDIT: Now more elegant without globals!

    function Twitter() {
       var dfd = $.Deferred();
       $.ajax({
          ...
          success: function(data) {
             dfd.resolve(data.count);
          }
       });
       return dfd.promise();
    }
    
    function Facebook() {
       var dfd = $.Deferred();
       $.ajax({
          ...
          success: function(data) {
             dfd.resolve(data.count);
          }
       });
       return dfd.promise();
    }
    
    $.when(Twitter(), Facebook()).then(function(twitter, facebook) {
       alert('The total is ' + (twitter+facebook));
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have simple JavaScript code that is using the Ajax API for fetching a
I have some jquery ajax call that returns a simple string. The interpretation of
I have a simple ajax call like this: $.ajax({ url: u, type: POST, dataType:
I have a simple form that triggers an ajax call but as soon as
I have a simple ajax call: $.ajax({url: my_url_here, dataType: 'text', success: function(data, textStatus) {
I have a simple $.ajax call that returns a response that looks like this:
I have a simple ajax request that I am trying to call a web
I have a simple JS function that needs to get called when AJAX call
I have a script that makes an ajax call to yahoo API which then
I have made a simple code for ajax to call a page but it

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.