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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T11:00:32+00:00 2026-05-15T11:00:32+00:00

Now if that isn’t a weird question, I don’t know what is. But here

  • 0

Now if that isn’t a weird question, I don’t know what is.

But here is the problem: I have a function in my “onSelect” option that has to collect some data (through AJAX) and I have a function in my “onComplete” option that processes the just uploaded files based on the data “onSelect” collected.

However, with very small files, the “onSelect” hasn’t finished yet before the upload is complete and the “onComplete” fails because it lacks the necessary data. Bigger files work just fine.

So, I’m looking for a way to stall the upload of the file. To let it start only after the function in onSelect completed fetching the necessary data.

Any ideas?

Here is an example of the function that the onSelect triggers:

var foo = new Array();

function checkDB( event, queueID , fileObj )
{

    $.post( ajax_folder + 'fetchData' ,
            {
                ref: "someValue"
            } ,
            function( data ){

                foo[ queueID ] = data.result;

            } ,
            'json' );

    return true;
}
  • 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-15T11:00:33+00:00Added an answer on May 15, 2026 at 11:00 am

    I generally agree with Peter that you should try and tap into the events more elegantly. However, you can (and probably should) extract that code into a function and keep a flag that tells you if it’s been called before. Something like this:

        var foo = new Array();
        var flag = false;
    
        function checkDB()
        {
            $.post( ajax_folder + 'fetchData' ,
                    {
                        ref: "someValue"
                    } ,
                    function( data ){
    
                        foo[ queueID ] = data.result;
                        flag = true;
                    } ,
                    'json' );
    
            return true;
        }
    
        function onSelectHandler(event, queueID , fileObj){
    
                checkDB();
    
        }
    
    function someOnCompleteStuff(){
       if(flag){
          //do oncomplete stuff
       }else{
          // try again later
          setTimeout(someOnCompleteStuff,500);
       }
    }
    
    function onCompleteHandler(event, queueID , fileObj){
            someOnCompleteStuff();
        }
    

    Of course you could always check the length of foo instead of using a flag.

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

Sidebar

Related Questions

Now that it's answered: Don't bother reading this question, it's a bit lengthy and
I asked a similar question before, but I only realized now that the answer
I know this question isn't directly programming related, but since I want to be
I've been trying to solve a slow trigger problem and now that I have
Now that I know I can no longer communicate with Twitter mashups out there,
Now that I have decided upon Firebird , with the help of StackOverflow :),
Now that Google Earth has been released for Android 2.1, does anyone know what,
Now that I have a read-only application working, I am working on the insert
Now that C++ development has become second nature to me, do I have to
I have a javascript function that appends elements into my HTML page. I want

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.