title: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded error
body: <p>I know that the above question has been asked many times. But those did not solve my problem.
  Here is the problem statement :</p>
  
  <p>I am trying to download zip file using 'ajax', I have read many posts that <strong>FILE DOWNLOAD IS NOT POSSIBLE USING AJAX</strong>
  So I tried to hack it, I don't know my approach is correct or not, I just tried it.</p>
  
  <p>So what am I doing is .. I am sending the byte from My controller. to my ajax call, and trying to make it downloadable.</p>
  
  <p>here is my ajax call </p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code> $.ajax({
              type: "POST",
              url: 'myURL',
              data: JSON.stringify(ajaxData),
              dataType: "json",
              contentType: "application/json",
              crossDomain: true,
              accept: "application/zip",
              success: function (data) {
              // i get the data here from my controller 
              var sampleBytes = base64ToArrayBuffer(data);
                  saveByteArray([sampleBytes], 'black1x1.gif');
  
                  function base64ToArrayBuffer(base64) {
                      console.log("base64ToArrayBuffer called");
                      var binaryString = window.atob(base64);
                      var binaryLen = binaryString.length;
                      var bytes = new Uint8Array(binaryLen);
                      for (var i = 0; i &lt; binaryLen; i++) {
                          var ascii = binaryString.charCodeAt(i);
                          bytes[i] = ascii;
                      }
                      return bytes;
                  }
  
                  var saveByteArray = (function () {
                      var a = document.createElement("a");
                      document.body.appendChild(a);
                      a.style = "display: none";
                      return function (data, name) {
                          var blob = new Blob(data, { type: "octet/stream" }),
                              url = window.URL.createObjectURL(blob);
                          a.href = url;
                          a.download = name;
                          a.click();
                          window.URL.revokeObjectURL(url);
                      };
                  }());
              },
              error: function (data) {
              }
          });</code></pre>
  </div>
  </div>
  </p>
  
  <p>But when I convert the data to base64, I get the above error.
  please, don't mind, I might be doing some foolish thing, I just tried,
  can any one help me to solve the problem. </p>