How do I use jquery to both download & delete files dynamically from servlet
Posted
by Adam
on Stack Overflow
See other posts from Stack Overflow
or by Adam
Published on 2010-04-29T20:31:11Z
Indexed on
2010/04/29
20:37 UTC
Read the original article
Hit count: 148
Is it possible to a jquery $.get() to call a servlet and use it to both download a file or update the page without reloading the page? (Or more basically, can I download a file without reloading the page?)
For example, I am using a servlet that either returns a file to download of mimetype "application/octet-stream", or returns text to be update in the page of type "text/html".
I can write a form with a submit, but then it reloads the page, so I've been trying to use $.get()... but the download doesn't work.
<script type="text/javascript">
jQuery(document).ready(function(){
$("#handleFileOptions button").button();
});
function handleFilesSubmit(requestType)
{
$.get('FileServlet', {filename: $('#radioFileList input:radio:checked').button("widget").text(), requestType: requestType}, function(data){ ...?... });
}
</script>
In the html:
<div id = "handleFiles">
<div id ="radioFileList">
<div id="radioFileList">
<input value="file0.txt" type="radio" id="fileitem0><label for="fileitem0">file0.txt</label>
<input value="file1.txt" type="radio" id="fileitem1><label for="fileitem0">file1.txt</label>
</div>
</div>
<div id="handleFileOptions">
<button id="handleFileOption0" onclick="handleFilesSubmit('Download')">Download</button>
<button id="handleFileOption1" onclick="handleFilesSubmit('Delete')">Delete</button>
</div>
</div>
© Stack Overflow or respective owner