协议方案仅支持跨源请求:http,data,chrome,chrome-extension,https [英] Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https

查看:2342
本文介绍了协议方案仅支持跨源请求:http,data,chrome,chrome-extension,https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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


$ b XMLHttpRequest不能加载文件:/// C:/wamp/www/TTT_BR/english.xml。只有协议方案支持交叉原始请求:http,data,chrome,chrome-extension,https。

解决方案

您必须在服务器上运行您的应用程序,使用节点js



1-安装NodeJS //提示:如果您使用Mac,则需要安装和使用Homebrew for this



2-打开您最喜爱的终端模拟器



2-运行http- code> npm install http-server -g



<3-> 3-运行http-server: http -server'path / to / your / angular / root / directory'-o



最后一个命令 - 具体地说是-o标志 - 应打开一个浏览器窗口:localhost:8080

或者使用cd查找你的目录应用程序
并使用以下命令: http-server。 -o



。意思是你当前的目录



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


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.

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.

解决方案

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

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

2- Open your favorite terminal emulator

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

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

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

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

"." mean your current directory

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

这篇关于协议方案仅支持跨源请求:http,data,chrome,chrome-extension,https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆