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

  • Home
  • SEARCH
  • 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 7419061
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:59:40+00:00 2026-05-29T07:59:40+00:00

This could either be very simple or quite complex I’m not sure at this

  • 0

This could either be very simple or quite complex I’m not sure at this point.

I’m writing a little web-app that will do a cinema schedule based on the Cineworld API.

I’m pulling back the data using AJAX and that’s fine, but I’ve got to the point where I want to get all the times for all of the selected films and then go on to manipulate them later, but combining all the results is proving a bit of a problem.

The resulting API call can only be done on a single film, so I have to pull back the data for each film in turn.

You can see the current, very early, state of the app here: http://www.lewishowles.co.uk/film/

And the main guts is in this file: http://www.lewishowles.co.uk/film/js/lh.js

Lines 42 and 206 are my issues. 42 always logs an empty array, but if I log the array down by 206 each time, it’s fine. Logging obviously isn’t going to help me much though. It looks like the log on 42 isn’t waiting for all of the code in the functions above it to finish.

As you can see I’ve tried a global array, I’ve tried returning values but it still seems to be running the log too quickly.

Deferred seems like it would usually be the case, but there will be a different number of ajax calls each time and it seems like you need to know how many to use Deferred.

Setting async to false stopped them tripping over each other, but that’s not helping this situation.

Two things I can think of are using Session Storage or hiding the results of each loop in HTML somewhere that I’ll then have to access later, but both of those seem like they’ll be prone to the same issues.

Another idea is to have another button to press so that the data has time to load, but that adds another step and isn’t ideal.

Any ideas?

  • 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-29T07:59:41+00:00Added an answer on May 29, 2026 at 7:59 am

    If you want to fire off a number of ajax calls and then know when they have all completed, there are a number of ways to do that.

    The simplest is to just keep a counter of how many ajax calls are in-flight. Then, when each one finishes, you decrement the counter (in the success handler) and if the counter gets to zero, you call the function that you want to execute when all the data is available.

    In pseudo-code, it could work like this for asychronous ajax calls:

    function runAjaxRequests(listOfRequests) {
        var ajaxCntr = listOfRequests.length;
        var ajaxResults = [];
    
        // fire off all the ajax requests
        for (var i = 0; i < listOfRequests.length; i++) {
            $.ajax(..., function(data) {
                // ajax success handler
    
                // store data returned from this request into ajaxResults
                ajaxResults.push(...);
    
                // see if all ajax requests are now done
                --ajaxCntr;
                if (ajaxCntr == 0) {
                    // all data has been returned, we can process it now
                    processAllAjaxData(ajaxResults);
                }
            })
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just could not get this one and googling did not help much either.. First
I have a very odd issue trying to run this quite simple C program
This could be a little off the ballpark, but a friend asked me about
This could quite possibly be the dumbest question ever asked. Our client wants us
This could save me so much time. Sometimes I find myself writing things like
I have built a variety of little scripts using Ruby's very simple Queue class,
This seems like a very simple problem, but I cannot get a scrollbox to
I've created a very simple app, which presents an easygui entrybox() and continues to
Either I'm very tired or something weird is happening that I'm not aware of,
I currently have a very simple web application written in Django, and I would

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.