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

Access-Control-Allow-Origin Errors #124

Closed
acahir opened this issue Jun 28, 2017 · 8 comments
Closed

Access-Control-Allow-Origin Errors #124

acahir opened this issue Jun 28, 2017 · 8 comments

Comments

@acahir
Copy link

acahir commented Jun 28, 2017

Have you found a way to resolve the errors on submit? They don't seem to affect success, but just wondering if there's any way to work around them.

@mckennapsean
Copy link
Collaborator

Not sure what you mean... do you have an example with this being shown? Typically, the errors I have seen as in the title have caused people's scripts NOT to work, so it is refreshing to hear that it is working for you at least!

@acahir
Copy link
Author

acahir commented Jun 29, 2017

You should been able to see them if you look at the console when you submit. Has to do with cross-site scripting. There's a setting that can be changed on the server I think, but unsure. One solution is a hidden iframe, but for now I'm just ignoring the errors.

I did get it to work, thanks very useful. Would have taken me a long time to figure out the Google side of it since I'd never looked at their scripts/web apps. Played around it with for a little bit before I had it working, but it's pretty straight forward overall. Ended up changing most of the handler.js since I'm just doing a simple email submission form and only want it logged into the spreadsheet.

@mckennapsean
Copy link
Collaborator

I have not seen these errors in working examples, such as https://dwyl.github.io/html-form-send-email-via-google-script-without-server/test.html

Glad you were able to get it to work though! Yes, you can configure headers and change things on the server, or change however you have created your page/form. But, as I show above, I have not seen these errors on that test form using the latest version of Chrome. Feel free to let me know if you do, though. I would love to figure out how to help people solve these issues, but I have not been able to reproduce them myself.

@acahir
Copy link
Author

acahir commented Jun 30, 2017

Now I'm really puzzled, as I didn't see the error on your test page as either.

Yet I tried many different setup configs (matching your setup of hosting submit script by rawgit, included in js located with webworm, etc). I didn't try hosting the webpage with the form at github...wonder if it's an allowed domain.

You can see the error message from the web console below (just had the domain name beneath black):

errormessage

Even with that error the submission goes through.

@mckennapsean
Copy link
Collaborator

Sufficed to say, this error leads to a very complex topic:
https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS

Could you try taking our test demo and hosting it on your site where you see the error?

It is possible that if you take all remote/non-local assets (such as the Javascript file, the Pure.css, etc.) then host & link them on your server instead that the error may disappear. I'd love to get this figured out so we can help those with similar issues - thank you!

@acahir
Copy link
Author

acahir commented Jun 30, 2017

Yea, it's not straightforward, even why it happens in one case and not another. I've see it occur enough over the years that I'm more surprised why it's not happening for you, which is why I asked if you had done something.

My script is extremely customized, I'm not calling any of your css or images. And In final version even have the js handler functions included in my common js file, hosted with the html file. Still happens then.

Tried many things yesterday, probably can't even remember them all:

  • Calling your js file hosted on rawgit
  • hosting file myself locally
  • hosting js file
  • moving POST URL from form tag to js function
  • used jQuery to post instead of xhr
  • ??? maybe others I'm forgetting.

There is a solution using an iframe mentioned in one of the sources your listed, but I hate hiding iframes, seems like such a hack.

@mckennapsean
Copy link
Collaborator

Strange. Not sure if it is something to do with the server then, and GitHub pages won't throw this error?

I agree that the iframe "solution" feels like hack (and likely only hides the error due to it being in an iframe). I really wish I knew what to advise for everyone having these issues.

@mckennapsean
Copy link
Collaborator

feel free to reopen with more details, trying to triage these issues together. may relate to #154, though the errors look different

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