Q:

word document from ajax response

I download a file from a server and want to create a word document from ajax response. Everything is ok when the file is .txt but it fails when it's .doc or .xls
Here is what i do
let settings = {
      "url": `${Constante.URL`,
      "headers": {
        "Authorization": sessionStorage.getItem('authorization')
      }
    };

    $.ajax(settings)
      .done(response => {
        fs.writeFile('file.doc', response, (err) => {
          const  exec = require('child_process');

          exec('file.doc', (err, stdout, stderr) => {
            if (err) {
              console.error(err);
              return;
            }
          });
      })
      .fail(err => {
        showError(err);
      });

Here is what i get when i open it

A:

If someone needs it I have achieved it with the following:
let xhr = new XMLHttpRequest();
  xhr.open('GET', `${Constante.URL}`, true);
  xhr.setRequestHeader("Authorization", sessionStorage.getItem('authorization'));
  xhr.responseType = 'arraybuffer';

  xhr.onload = function(e) {
    if (this.status == 200) {
       fs.writeFileSync(path.resolve(app.getAppPath(), 'tmp', filename), Buffer.from(new Uint8Array(this.response)));
    }
  };

  xhr.send();

