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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T19:47:21+00:00 2026-05-31T19:47:21+00:00

I recently ran into a familiar javascript/jQuery timing bug and spent too long debugging

  • 0

I recently ran into a familiar javascript/jQuery timing bug and spent too long debugging it. What I need is a smarter debugging path for this problem.

In specific, my issue was that user inputs were supposed to be causing a Mongo database call and the results were sent, after a little math, to displayed outputs. But the displayed outputs were crazily wrong. However, once I added a FireBug break point the problem went away. At that point I knew I had a timing issue, but not how to solve it.

Here are the relavant pieces of code before the error:

handleDataCallBack : function(transport) {
   var response = $.parseJSON(transport);

   if(!hasErrors) { this.updatePage(response); }
},

accessDatabase : function(){
   var params = { ... };
   DAL.lookupDatabaseInfo(this.handleCallBackOutputPanel, this, params);
},

calculateValues: function() {
   // some numerical values were updated on the page
}

onDomReady : function() {
// ...
   //bind drop-down select change events
   $('#someDropDown').change(function() {
      me.accessDatabase();
      me.calculateValues();
   });
}

To fix the problem, all I had to do was move the “calculateValues” method from the onDomReady inside the call back:

handleDataCallBack : function(transport) {
   var response = $.parseJSON(transport);

   this.calculateValues();
   if(!hasErrors) { this.updatePage(response); }
},

The problem was that the database hadn’t responded before the calculations were started. Sure, that’s easy to spot in retrospect. But what methods can I use to debug asynchronous timing issues in javascript/jQuery in the future? This seems well outside the context of IDE tools. And FireBug didn’t help. Are there any tools for tracking down asynchronous web development issues? Or maybe some time-tested methods?

  • 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-31T19:47:21+00:00Added an answer on May 31, 2026 at 7:47 pm

    i assume your problem is caused here:

    $('#someDropDown').change(function() {
        me.accessDatabase();
        me.calculateValues();
    });
    

    this issue is that your calculations are done just right after the call. seeing that the DB call is async, calculate does not wait for it. however, you can do it using “callbacks”. i see you do try to implement it and yes, it is correct. however, i find this more elegant:

    calculateValues: function() {
        // some numerical values were updated on the page
    },
    
    //since this is your general callback hander
    //you hand over the return data AND the callbackAfter
    handleDataCallBack: function(transport, callbackAfter) {
        var response = $.parseJSON(transport);
    
        //you may need to use apply, im lost in scoping here
        callbackAfter();
        //or
        callbackAfter.apply(scope);
    
        if (!hasErrors) {
            this.updatePage(response);
        }
    },
    
    accessDatabase: function(callbackAfter) {
        var params = {};
    
        //pass callbackAfter to the function,
        //after this is done, pass it to the handler
        DAL.lookupDatabaseInfo(this.handleCallBackOutputPanel, this, params, callbackAfter);
    },
    
    onDomReady: function() {
        $('#someDropDown').change(function() {
            me.accessDatabase(function() {
                //send over what you want done after. 
                //we'll call it "callbackAfter" for easy tracing
                me.calculateValues();
            });
        });
    }​
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I recently ran into a bug with the linux stack and the linux stack
I've recently ran into a bit of a pain. I've been using the JQuery
Premise I recently ran into a bug in a select statement in my code.
We recently moved to jQuery 1.6 and ran into the attr() versus prop() back-compat
I recently ran into a problem where it seems I need a 'static abstract'
I recently ran into a very sneaky bug, in which I forget to dereference
I recently ran into some troubles using JQuery Draggable and Resizable plugins. Looking for
I recently ran into a problem that I thought boost::lambda or boost::phoenix could help
I recently ran into a issue where intermediate link betweeen a TCP server and
I recently ran into a problem with a COM object that was using a

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.