jquery - Listening for form submit -> file download Event -


in jsp file, have simple form:

<form action="#" method="post" id="extract_form"> 

and based on few select parameters, returns .zip file through piece of code in servlet:

servletoutputstream sos = response.getoutputstream(); response.setcontenttype("application/zip"); response.setheader("content-disposition", "attachment; filename=\"" + zipfile.getname() + "\""); 

-followed sos.write(bytearray);

all working excellent, time takes create zip file dependent on form parameters , display "please wait" blockui popup on form submit , removed again automatically when .zip file has been received browser.

i have no trouble displaying popup, have hard time getting disappear again automatically after file received! how accomplish this?

if have tried following:

1: explicit $.unblockui() in

jquery(document).ready(function($) { ... } 

-but ready() event not triggered after .zip file sent, i.e., .jsp not reloaded.

2: solution this one. success callback function called, .zip file not downloaded. think, though, .zip file transferred browser in binary form through response object passed function called on success.

3: scanning jquery webpage events listen to, found on triggering of action ($('#form').submit(...)), not response thereof.

oh, eureka!

i changed return false return true in $.post , works!

var $form = $('#extract_form'); $form.submit(function(){     $.post($(this).attr('action'), $(this).serialize(), function(response) {         $.unblockui();     }, 'text');     return true; }); 

Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -