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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T06:28:13+00:00 2026-06-13T06:28:13+00:00

I have 4 different JQuery AJAX functions, each fetching different information from the last.fm

  • 0

I have 4 different JQuery AJAX functions, each fetching different information from the last.fm API. This info has to be joined together in a tooltip.

These are my 4 functions:

  1. Gets the album for a given track & artist. Returns track name.
  2. Gets the artist image. Returns 1 URL.
  3. Gets the top 3 albums of the artist. Returns array of 3 strings.
  4. Gets the #1 top track of a given artist. Returns track name.

 

var getTrackAlbum = function(track, artist) {
    $.getJSON(
      settings.PHP_REQUEST_URL,
      {
        method: "track.getInfo",
        api_key : settings.LASTFM_APIKEY,
        track   : track,
        artist  : artist,
        format  : "json"
      },
      function(data) {
        return data.track.album.title;
      });
}

var getArtistImage = function(artist) {
    var options = {
      artSize: 'medium',
      noart: 'images/noartwork.gif',
    }

    if(options.artSize == 'small'){imgSize = 0}
    if(options.artSize == 'medium'){imgSize = 1}
    if(options.artSize == 'large'){imgSize = 2}

    $.getJSON(
      settings.PHP_REQUEST_URL,
      {
        method: "artist.getInfo",
        api_key : settings.LASTFM_APIKEY,
        artist  : artist,
        format  : "json"
      },
      function(data) {
        return stripslashes(data.artist.image[imgSize]['#text']);
      });
}

var getArtistTopAlbums = function(artist) {
    var albums = new Array();

    var onComplete = function() {
      return albums;
    }

    $.getJSON(
      settings.PHP_REQUEST_URL,
      {
        method: "artist.getTopAlbums",
        api_key : settings.LASTFM_APIKEY,
        artist  : artist,
        format  : "json"
      },
      function(data) {
        $.each(data.topalbums.album, function(i, item){
          albums[i] = item.name;

          if(i == 2) { 
            onComplete.call(this);
            return;
          }
        });
      });
}

var getArtistTopTrack = function(artist) {
    $.getJSON(
      settings.PHP_REQUEST_URL,
      {
        method: "artist.getTopTracks",
        api_key : settings.LASTFM_APIKEY,
        artist  : artist,
        format  : "json"
      },
      function(data) {
        return data.toptracks.track[0].name;
      });
}

I have decided against doing all the requests inside a unique method for reuse purposes. However, now I want to wait for ALL the AJAX requests to complete before I set the HTML of my tooltip.

Here’s the code of my tooltip:

$('.lfm_info').on('mouseover', function(){
          var toolTip = $(this).children('.tooltip');

          var trackhtml = $(this).parent().children('.lfm_song').html().split(".");
          var track = trackhtml[1].trim();
          var artist = $(this).parent().children('.lfm_artist').html();

        // needs to wait until the AJAX is done!    
        toolTip.html('html here');

        $('#tracks').mouseleave(function(){
         if(toolTip.is(':visible')){
           toolTip.fadeOut(500);  
         };    
       });

        toolTip.fadeIn(500);      
      });
}

How would I wait for all requests to complete before invoking toolTip.html(...)?

  • 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-13T06:28:14+00:00Added an answer on June 13, 2026 at 6:28 am

    Store each request, then use $.when to create a single deferred object to listen for them all to be complete.

    var req1 = $.ajax({...});
    var req2 = $.ajax({...});
    var req3 = $.ajax({...});
    
    $.when( req1, req2, req3 ).done(function(){
        console.log("all done")
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have different php output in jQuery-based tabs. This output is formed from database
I have jQuery functions; e.g A(), B() and C() Each function makes some Ajax
I have found and customized this JQuery script, which displays different content when different
I am using jQuery fullcalendar plugin , I have tried altering this many different
I have an ajax call in jquery which returns 4 different arrays. 3 of
I have 3 different jquery uses & put it into one code as follows:
I have a jquery flexigrid that I'm dynamically changing so that it displays different
I have mostly all of my forms for different controllers in a jquery dialog
I need to have a JQuery color Picker, where I can change the different
I'm trying to test some jQuery ajax code using QUnit and Mockjax and 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.