javascript XMLHttpRequest 无法加载文件。跨源请求仅支持 HTTP。angular.js
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23681965/
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
XMLHttpRequest cannot load file. Cross origin requests are only supported for HTTP. angular.js
提问by Quv
I posted a question a couple of days ago regarding me making a copy of a popular website.
几天前我发布了一个关于我复制一个流行网站的问题。
What I'm looking to do is to do an exact copy of a mobile version of a website, I'm aware its a responsive design, so I enabled emulation in chrome and copied the source it showed, however it throws out errors constantly, which I guess is due to security issues, but I'm totally baffled at how to get around it, below are the errors i'm receiving.
我想要做的是做一个网站的移动版本的精确副本,我知道它是一个响应式设计,所以我在 chrome 中启用了模拟并复制了它显示的源代码,但是它不断抛出错误,我猜这是由于安全问题,但我完全不知道如何解决它,下面是我收到的错误。
GET file://static.o2.co.uk/shared/js/lib/jquery-2.0.3.min.js?bust=161309052014 net::ERR_FILE_NOT_FOUND require.js:34
Uncaught Error: Script error for: jquery
http://requirejs.org/docs/errors.html#scripterror require.js:8
GET file://static.o2.co.uk/shared/js/lib/le-mtagconfig.js?bust=161309052014 net::ERR_FILE_NOT_FOUND require.js:34
Uncaught Error: Script error for: lib/le-mtagconfig
http://requirejs.org/docs/errors.html#scripterror require.js:8
Uncaught Error: Load timeout for modules: o2/o2.min,plugins.jquery
http://requirejs.org/docs/errors.html#timeout require.js:8
GET file://lptag.liveperson.net/tag/tag.js?site=63960994 net::ERR_FILE_NOT_FOUND le-mtagconfig.js:1
GET file://servedby.o2.co.uk/container/2746;14241;1752;iframe/?ft_referrer=file…//C%3A/Users/Reece/Desktop/Mobile/testing123.html&ns=&cb=371028.8053844124 net::ERR_FILE_NOT_FOUND tracking.min.js:1
XMLHttpRequest cannot load file:///C:/Users/Reece/Desktop/Mobile/api/userdetails?disambiguation_id=. Cross origin requests are only supported for HTTP. angular.js:7836
Error: A network error occurred.
at Error (native)
at http://static.o2.co.uk/mymobile/js/lib/angular.min.js:72:139
at z (http://static.o2.co.uk/mymobile/js/lib/angular.min.js:68:173)
at h (http://static.o2.co.uk/mymobile/js/lib/angular.min.js:66:157)
at z (http://static.o2.co.uk/mymobile/js/lib/angular.min.js:91:280)
at http://static.o2.co.uk/mymobile/js/lib/angular.min.js:92:417
at g.$eval (http://static.o2.co.uk/mymobile/js/lib/angular.min.js:100:328)
at g.$digest (http://static.o2.co.uk/mymobile/js/lib/angular.min.js:98:210)
at g.$apply (http://static.o2.co.uk/mymobile/js/lib/angular.min.js:101:157)
at http://static.o2.co.uk/mymobile/js/lib/angular.min.js:17:415 angular.js:9101
ReferenceError: $ is not defined
From what I understand so far, it won't run the code as its not being hosted on the original site, but surely theres a way for me to get an exact copy of the site
据我目前所知,它不会运行代码,因为它没有托管在原始站点上,但肯定有办法让我获得该站点的精确副本
Any help is greatly appreciated !
任何帮助是极大的赞赏 !
When loading up the page on firefox, I receive the following warnings;
在 Firefox 上加载页面时,我收到以下警告;
Error: http://static.o2.co.uk/mymobile/js/lib/angular.min.js is being assigned a //# sourceMappingURL, but already has one
Error: http://static.o2.co.uk/mymobile/js/lib/angular-route.min.js is being assigned a //# sourceMappingURL, but already has one
Error: http://static.o2.co.uk/mymobile/js/lib/angular-sanitize.min.js is being assigned a //# sourceMappingURL, but already has one
Error: Script error for: jquery
http://requirejs.org/docs/errors.html#scripterror require.js:8
Error: Script error for: lib/le-mtagconfig
http://requirejs.org/docs/errors.html#scripterror
回答by Quv
I think it's simply because Chrome doesn't allow you to send XmlHttpRequest to your local file. It will work if you bring your app onto the server. Use another browser or add this options.
我认为这仅仅是因为 Chrome 不允许您将 XmlHttpRequest 发送到您的本地文件。如果您将应用程序带到服务器上,它将起作用。使用其他浏览器或添加此选项。
--allow-file-access-from-files
This answer looks nice. XMLHttpRequest cannot load file. Cross origin requests are only supported for HTTP
这个答案看起来不错。 XMLHttpRequest 无法加载文件。跨源请求仅支持 HTTP