eligrey / eligrey/FileSaver.js

Update HTML page after saveAs is executed

Open
#631 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
22k
Forks
4.3k
PR merge metrics
No merged PRs in 30d

Description

Hola,

for the purpose of my service I need to update html page in order to dispaly a piece of response data to the end-user. I need to implement this alongside with downloading file.

Here is my code:

```js
import { saveAs } from "./FileSaver";

$(document).on('submit', '#certreq', function (e) {
e.preventDefault();
$.ajax({
type: 'POST',
url: '',
data: {
cn: $('#id_cn').val(),
san: $('#id_san').val(),
ou: $('#id_ou').val(),
env: $('#id_env').val(),
email: $('#id_email').val(),
csrfmiddlewaretoken: $('input[name=csrfmiddlewaretoken').val(),
},
success: function (response, status, request) {
document.getElementById('certreq');
// var type = request.getResponseHeader('Content-Type')
var blob = new Blob([response], { type: "application/zip" });
var filename = request.getResponseHeader('Filename'); // this one also does
saveAs(blob, filename);
console.log(request.getAllResponseHeaders());
var header = request.getResponseHeader('Message');
$('.messages').prepend('

' +
'
' +
'
' +
'

' + '' + 'Ваш запрос успешно выполнен' + '' + '

' +
'

' + 'Ваш пароль сертификата: ' + header + '

' +
'
' +
'
' +
'
')
},
});
})`
```

as you might see, I submit an ajax request for the form I defined and created using django. As the form is submitted successfully, I'm trying to do both: download file to my desktop and to display a piece of output data in the browser.

However, as the first thing is executed perfectly (my zip file is downloaded and is not corrupted, it contains all the data I want it to), the second does not happen. I can't see my data displayed.

What am I doing wrong ? I am desperate a bit, been struggling this for almost a week.

If some to be clarified, tell, I'll explain

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.