Access to XMLHttpRequest at 'file:///D:/register' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome-untrusted, https, edge. register.html:64 {readyState: 0, getResponseHeader: ƒ, getAllResponseHeaders: ƒ, setRequestHeader: ƒ, overrideMimeType: ƒ, …} jquery-3.6.0.min.js:2 POST file:///D:/register net::ERR_FAILED
时间: 2024-04-15 21:26:39 浏览: 26
这个错误是由于浏览器的安全策略导致的,称为CORS(跨域资源共享)策略。浏览器默认情况下禁止通过XMLHttpRequest从本地文件系统访问不同源的资源。
你正在尝试从本地文件系统("file://")发起一个POST请求到一个不同的源("http://"或"https://"),这是不被允许的。
为了解决这个问题,你可以将你的网站部署到一个支持HTTP或HTTPS协议的web服务器上,然后通过服务器访问资源。这样就可以避免CORS错误。
另外,如果你只是想在本地测试,你也可以尝试使用一些本地服务器软件,如Node.js的http-server或Python的SimpleHTTPServer来运行你的网页。这些服务器会在本地创建一个HTTP服务器,允许你通过"localhost"或"127.0.0.1"来访问你的网页,并且可以避免CORS错误。
相关问题
Access to XMLHttpRequest at 'file:///D:/register' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome-untrusted, https, edge.
这个错误是由于浏览器中的CORS(跨源资源共享)策略导致的。CORS是一种浏览器安全机制,用于限制通过JavaScript发起的跨域请求。
在你的代码中,你正在尝试从本地文件系统(`file://`)访问`D:/register`,而不是通过HTTP协议来访问。浏览器默认情况下不允许从本地文件系统发起跨域请求。
要解决这个问题,你可以将你的应用程序部署到一个本地服务器上,例如使用Node.js的`http-server`模块。首先,使用以下命令全局安装`http-server`:
```
npm install -g http-server
```
然后,打开一个命令提示符窗口,进入到你的应用程序所在的目录,并运行以下命令来启动本地服务器:
```
http-server
```
默认情况下,服务器会监听`http://localhost:8080`。现在,你可以通过访问`http://localhost:8080/register`来发送请求,而不再遇到CORS错误。
另外,如果你的应用程序需要在本地文件系统中运行,你可以尝试使用某些浏览器插件或者在浏览器中禁用CORS策略来绕过这个错误。但请注意,这不是一个推荐的解决方案,因为禁用CORS可能会导致安全问题。
Access to XMLHttpRequest at 'file:///D:/index/login' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, isolated-app, chrome-extension, chrome, https, chrome-untrusted.
这个错误提示是由于浏览器的同源策略导致的。浏览器不允许从一个源站点去请求另一个源站点的数据。在你的代码中,你正在从本地的文件系统(file://)发送一个跨域请求(到一个不同的域名或IP地址),所以浏览器会拒绝这个请求。
要解决这个问题,你需要将你的代码部署到一个支持HTTP协议的Web服务器上,然后通过HTTP协议来发送请求。或者你可以通过修改浏览器的安全设置来禁用同源策略,但这并不是一个安全的做法,不建议在生产环境中使用。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)