I want Open/Save file dialog appears on page with notification about execution status.
JSP:
<head>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>
<script type="text/javascript" language="javascript">
function call() {
var msg = $('form').serialize();
$.ajax({
type: 'POST',
url: 'compressor',
data: msg,
success: function(data) {
$('#results').html("Success");
},
error: function(xhr, str){
$('#results').html("Failed");
}
});
}
</script>
</head>
<body>
<h2>Web compressor</h2>
<form method="post" action="javascript:void(null);" onsubmit="call()">
<table>
/*input*/
</table>
</form>
Result: <div id="results"></div>
</body>
Servlet: On input servlet gets, source file path and creates temporary file. After that i use:
response.setContentType("application/octet-stream");
response.setHeader("Content-disposition","attachment; filename="fileName");
And write file to OutputStream. But dialog pop-up doesn't appear, only "Success" message. Without ajax it works correctly. How can i solve this problem?