0

I am building a form on a Landing page, and I keep running into an error when I'm passing the javascript to the processing page. In the error console, I see the following:

Fetch failed loading: POST "https://xxxx.xxxx.xxx".
reader.onload @ page1:225
load (async)
getBase64 @ page1:216
(anonymous) @ page1:209

My javascript is:

<script runat="client">
  document.getElementById("button")
      .addEventListener("click", function() {
          var files = document.getElementById("file").files;
          if (files.length > 0) {
              getBase64(files[0]);
          }
      });

  function getBase64(file) {
      var reader = new FileReader();
      reader.readAsDataURL(file);
      reader.onload = function() {

          //prepare data to pass to processing page 
          var fileEncoded = reader.result;
          var base64enc = fileEncoded.split(";base64,")[1];
          var fullFileName = document.getElementById("file").files[0].name;
          var fileName = fullFileName.split(".")[0];
          var assetName = fullFileName.split(".")[1];

          fetch("https://xxxx.xxxx.xxx", {  //provide URL of the processing page
                  method: "POST",
                  headers: {
                      "Content-Type": "application/json"
                  },
                  body: JSON.stringify({
                      base64enc: base64enc,
                      fileName: fileName,
                      assetName: assetName
                  })
              })
              .then(function(res) {
                      window.alert("Success!");
              })
              .catch(function(err) {
                  window.alert("Error!");
              });
      };
      reader.onerror = function(error) {
          console.log('Error: ', error);
      };
  }
</script>

The result does seem to go on to the processing page, but I'm afraid it is holding back other functions on the processing page.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.