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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:52:21+00:00 2026-05-22T00:52:21+00:00

I have a form which allows to view data in a page or download

  • 0

I have a form which allows to view data in a page or download it in csv according to the submit button pressed.

Since it’s a long database query I want to avoid the user to submit more than once (you know how heavy is users’ index finger on left mouse button…) to avoid database overload and also to make user more relaxed…

I wrote this little jQuery code to substitute submit button(s) with a Processing, please wait and the classic animated spinning gif

$(document).ready(function(){
    //preload wait img
    var $waitImg = $('<img />').attr('src', '/img/wait.gif')
    $('.wait').click(function(){
        $(':submit').hide();
        $(this).after($('<span>Processing, please wait...</span>').prepend($waitImg));
    });
});

All works but has some drawbacks:

  • when user sees results and then press the browser’s back button he will get again the Processing, please wait sentence and no submit buttons (what if he just wants to edit something and make a new query)
  • after user is prompted to download the CSV file he keeps on being told to wait…

Solutions could be to detect someway user is back or download stared or another way to tell him work is in progress.

The easier, the better.

  • 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-22T00:52:22+00:00Added an answer on May 22, 2026 at 12:52 am

    Found this:

    Detecting the File Download Dialog In the Browser

    and this is my code based on it:

    html

    <form ...> 
        <fieldset> 
        ...
        <div> 
            <input class="wait" id="submit" name="submit" type="submit" value="View" /> 
            <input class="wait" id="submit" name="submit" type="submit" value="Download as CSV" /> 
        </div> 
        </fieldset> 
    </form> 
    

    javascript

    $(document).ready(function(){
        var cookieCheckTimer;
        var cookieName = 'download_token';
        var $wait = $('.wait');
        var $waitMsg = $('<span>Processing, please wait...</span>').prepend(
            $('<img />').attr('src', '/img/wait.gif').css({
                'vertical-align': 'middle',
                'margin-right': '1em'
            }));
        //add hidden field to forms with .wait submit
        $wait.parent().each(function(){
            $(this).append($('<input />').attr({
                'type': 'hidden',
                'name': cookieName,
                'id': cookieName
            }));
        });
        $wait.click(function(){
            var token = new Date().getTime();
            //set token value
            $('#' + cookieName).val(token);
            //hide submit buttons
            $(':submit').hide();
            //append wait msg
            $(this).after($waitMsg);
    
            cookieCheckTimer = window.setInterval(function () {
                if ($.cookie(cookieName) == token){
                    //clear timer
                    window.clearInterval(cookieCheckTimer);
                    //clear cookie value
                    $.cookie(cookieName, null);
                    //detach wait msg
                    $waitMsg.detach();
                    //show again submit buttons
                    $(':submit').show();
                }
            }, 1000);
        });
    });
    

    Server side if a download_token key is found in request parameters a cookie with its name and value is set.

    Here’s my python (pylons) code for a controller’s __before__ :

    python

    cookieName = 'download_token'
    #set file download coockie if asked
    if cookieName in request.params:
        response.set_cookie(cookieName,
            #str: see http://groups.google.com/group/pylons-discuss/browse_thread/thread/7d42f3b28bc6f447
            str(request.params.get(self._downloadTokenName)),
            expires=datetime.now() + timedelta(minutes=15))
    

    I set cookie expire time to 15 minutes to not fill up client cookies, you choose an appropriate duration based on time needed by task.

    This also will work with browser back button issue as when going back the cookie will be found and buttons restored.

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

Sidebar

Related Questions

I have a form which users must fill out and submit. The controller action
I have a Rails view (recipes/new) which allows users to enter a new recipe.
I have a form which is used to insert/display and update . In the
I have a form which takes both the user details and an image uploaded
I have a form which has a lot of SELECTs. For various reasons, I'd
I have a form which I create manually (a lot of JavaScript in it...).
I have a form which encapsulates all the functionality, but works with a concrete
I have a form which has only tab control in it. I want to
I have a form which is a mdicontainer and has a menu strip at
I have a form which users can add controls to and when they right

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.