У меня есть функция, отправки данных на почту из формы.  И когда данные отправлены, автоматически начинается скачивание pdf файла (downloadPdf(); ). Но почему-то их качается 2, а не 1. В чем проблема?
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
    xhr.onreadystatechange = function() {
        if (xhr.readyState === 4 && xhr.status === 200) {
          form.reset();
          hideAllSpinners(form);
          showThankMessage(form);
          window.setTimeout(function() {
            hideThankMessage(form);
            console.log('enable with timeout');
            enableAllButtons(form);
          }, 3500);
//ВОТ ТУТ
          downloadPdf();
        } else if (xhr.readyState === 4) {
          hideAllSpinners(form);
          console.log('enable with no timeout');
          enableAllButtons(form);
        };
    };
function downloadPdf() {
    let link = document.createElement('a');
    link.setAttribute('href','./images/pdf/Cutting-costs-on-UA-management.pdf');
    link.setAttribute('download', 'Cutting Costs on UA Management');
    link.click();
  };