Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Redirection after POST #64

Open
gpasquet opened this issue May 1, 2023 · 1 comment
Open

Redirection after POST #64

gpasquet opened this issue May 1, 2023 · 1 comment

Comments

@gpasquet
Copy link

gpasquet commented May 1, 2023

Hey,

Im looking to add a redirection after the POST.
I tried several different things without any success :(

Script still redirect to the JSON or Google App Script page

Best,

@bbowers-hawaii
Copy link

What worked for me was:

  1. set the Web App access/auth, "Who has access" to Anyone.
    you can do this in appscript by clicking Deploy, Manage Deployments, edit

  2. then in your html file after closing tag:

<script>
window.addEventListener("load", function() {
  const scriptURL = '<YOUR SCRIPT URL>'
  const form = document.getElementById('id of your form');
  form.addEventListener("submit", function(e) {
    e.preventDefault();
    const data = new FormData(form);
    fetch(scriptURL, {
      method: 'POST',
      body: data,
      mode: 'no-cors', // unsure if this is needed since access changed to anyone
    })
    .then(() => {
    window.top.location.href = 'your page url';
    })
  });
});
</script>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants