Javascript 跨源请求仅支持以下协议方案:http、data、chrome、chrome-extension、https

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/43936500/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 02:15:27  来源:igfitidea点击:

Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https

javascriptxmlgoogle-chromegoogle-chrome-extension

提问by Amit Golhar

I'm facing this issue with chrome and IE. I have developed HTML player in that i used XML to load the data inside that player. all pages have been accessed through XML.it work fine when I use any server to load that data inside player.I use WAMP server now. But now I'm thinking about making it as an offline version and write it inside CD. but when I open my player.html file directly without having server, the XML data not going to load.it showing following error in the console.

我正面临着 chrome 和 IE 的这个问题。我开发了 HTML 播放器,因为我使用 XML 加载该播放器内的数据。所有页面都已通过 XML 访问。当我使用任何服务器在播放器中加载该数据时,它工作正常。我现在使用 WAMP 服务器。但现在我正在考虑将其制作为离线版本并将其写入 CD。但是当我在没有服务器的情况下直接打开我的 player.html 文件时,XML 数据不会加载。它在控制台中显示以下错误。

XMLHttpRequest cannot load file:///C:/wamp/www/TTT_BR/english.xml. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

XMLHttpRequest 无法加载 file:///C:/wamp/www/TTT_BR/english.xml。跨源请求仅支持以下协议方案:http、data、chrome、chrome-extension、https。

回答by Hussein Saad

you must run your app in the server , use node js

你必须在服务器上运行你的应用程序,使用 node js

1- Install NodeJS // Hint: If you're on a Mac, you want to install and use Homebrew for this

1- 安装 NodeJS // 提示:如果你在 Mac 上,你想为此安装和使用 Homebrew

2- Open your favorite terminal emulator

2- 打开你最喜欢的终端模拟器

2- Install http-server by running: npm install http-server -g

2-通过运行安装http-server: npm install http-server -g

3- Start http-server by running: http-server 'path/to/your/angular/root/directory' -o

3- 通过运行以下命令启动 http-server: http-server 'path/to/your/angular/root/directory' -o

That last command — specifically, the -o flag — should open a browser window at: localhost:8080

最后一个命令——特别是 -o 标志——应该打开一个浏览器窗口:localhost:8080

OR// use cd to find your directory app
and use this command : http-server . -o

或// 使用 cd 查找您的目录应用程序
并使用以下命令:http-server . -o

"." mean your current directory

“。” 表示您当前的目录

you can see : https://teamtreehouse.com/community/i-am-not-able-to-load-my-json-file

你可以看到:https: //teamtreehouse.com/community/i-am-not-able-to-load-my-json-file

回答by meol

for testing/development purposes, the simplest solution is to use firefox browser.

出于测试/开发目的,最简单的解决方案是使用 firefox 浏览器。

回答by Nick Drozd

Pretty much everyone has python on mac/linux by default. Who doesent, can easily get it.

默认情况下,几乎每个人都在 mac/linux 上使用 python。谁不知道,可以轻松搞定。

python -m SimpleHTTPServerwill give you a local server @ http://localhost:8000. From there you can access whatever file you'd like for your app.

python -m SimpleHTTPServer会给你一个本地服务器@ http://localhost:8000。从那里您可以访问您想要的应用程序的任何文件。

Note: use python -m http.serverfor python versions 3.0+

注意:python -m http.server用于python 3.0+版本

回答by Christian Jeunesse Alegado

Or you can run a web server like Apache and MySQL in XAMPP Control Panel. Put your file folder inside /htdocs inside /xampp folder and run your code in the browser using localhost.

或者,您可以在 XAMPP 控制面板中运行 Apache 和 MySQL 等 Web 服务器。将您的文件夹放在 /htdocs 中的 /xampp 文件夹中,并使用 localhost 在浏览器中运行您的代码。