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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:53:05+00:00 2026-05-27T17:53:05+00:00

I’m currently working on an inherited project which uses Google’s Visualization API (for both

  • 0

I’m currently working on an inherited project which uses Google’s Visualization API (for both Python and Javascript). Since parsing the data for Gviz takes a while, I’m trying to let the page fetch a loading image and display it while the relevant charts are loading via AJAX calls.

While I could be wrong, I believe that I have been coding it correctly; below you can find the relevant code, which I have inserted into the <head> portion of the page.

$(function() {
    var dates = $("#from, #to").datepicker({
        numberOfMonths: 1,
        beforeShow: function() {
            var other = this.id == "from" ? "#to" : "#from";
            var option = this.id == "from" ? "maxDate" : "minDate";
            var selectedDate = $(other).datepicker('getDate');
            $(this).datepicker("option", option, selectedDate);
        },
        onSelect: function(dateText, inst) {
            drawCharts();
        }
    }).change(function() {
        var other = this.id == "from" ? "#to" : "#from";
        if ($('#from').datepicker('getDate') > $('#to').datepicker('getDate'))
            $(other).datepicker('setDate', $(this).datepicker('getDate'));
    });
    $("#from").datepicker("setDate", '-13');
    $("#to").datepicker("setDate", new Date());

    $("#weekly_cohorts").click(function() {
        weekly = true;
        drawCharts();
    });

    $("#monthly_cohorts").click(function() {
        weekly = false;
        drawCharts();
    });

    // ERROR OCCURS HERE
    google.load('visualization', '1', {packages:['corechart', 'table']});
    google.setOnLoadCallback(getData);
});

When I run this, Chrome’s JavaScript Console displays an error message along the lines of EVENT FIRED TOO FAST, which doesn’t make sense to me according to the jQuery API.

If I call the two lines earlier (i.e., outside of the $( handler )), however, I have no problems, but the preloading image isn’t fetched until it’s too late.

What’s going wrong, and how do I fix it? While I could just move the script to the end of the body, I prefer to have all my stylesheet and script references in the head.

EDIT: Chrome’s console no longer gives me that error, but since the page doesn’t fully render before the script is called, it can’t interact with the DOM. In addition, the image is still not fetched until after script execution.

Again, any ideas on how to delay script execution (triggered by the second line) from the DOMContent event to the Load event (i.e., until the page is fully rendered)?

EDIT 2: I briefly managed to get it to work as desired, but only after I restarted Chrome. However, I believe that was only because it was already stored in the local cache (i.e., HTTP Response code 304), since refreshing the page only brought back the “page not rendering before script is called” problem.

  • 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-27T17:53:06+00:00Added an answer on May 27, 2026 at 5:53 pm

    Edit: Put your call to google.load() in an img onload handler. Do not use jQuery for this, as the img may have already loaded by the time the ready handler is called.

    <img src="loading.gif" onload="loadCharts()" />
    
    function loadCharts () {
        google.load('visualization', '1', {packages:['corechart', 'table']}); 
        google.setOnLoadCallback(getData); 
    }
    

    Original answer:

    Is getData() your intended onload handler? Or does it return a function that you want to use as the onload handler? If it is itself the onload handler, remove the parentheses so as to return a function reference, rather than immediately calling the function:

    google.setOnLoadCallback(getData);
    

    But, if getData() does indeed itself return a function, and you need to delay your code execution until after the page has loaded, bind to the window.onload event:

    $(window).load(function () {
        ...
    });
    

    Instead of document.ready ($(function () { ... })).

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

Sidebar

Related Questions

I used javascript for loading a picture on my website depending on which small
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I am trying to understand how to use SyndicationItem to display feed which is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported
I am currently running into a problem where an element is coming back from
I have a text area in my form which accepts all possible characters from
I am writing an app with both english and french support. The app requests

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.