Posting from local html/javascript website to an online PHP file

后端 未结 2 1197
梦如初夏
梦如初夏 2021-01-14 10:25

What I\'m trying to do

Post from a local html/javascript website to an online PHP file.

Problem

When I attempt to

2条回答
  •  [愿得一人]
    2021-01-14 11:09

    Due to chrome security settings, to make an XMLHttpRequest you need a valid origin and a valid destination.
    The destination is a valid domain, and because you have Access-Control-Allow-Origin enabled, you can make a request from different origin.
    But the origin is not a valid domain, because you are doing a request from a local page.
    The origin must be a valid host/identifier (domain for a website, identifier for a browser extension, application id for a webview embedded into an application).

    You have these option to solve the issue:

    • Store your page on an host, that's fine localhost too, you can create a setup to automatically deploy the host and webpage to your customers
    • disable browser security settings: sample for chrome:

      chromium-browser --disable-web-security --user-data-dir

      check this answer, for how to use: https://stackoverflow.com/a/3177718/5081328

    • embed your page into an application and use a webview

    • Create a browser extension to load your page

提交回复
热议问题