错误消息“ XMLHttpRequest无法加载跨源请求仅在AngularJS中支持HTTP

【字号: 日期:2024-04-09浏览:59作者:雯心
(adsbygoogle = window.adsbygoogle || []).push({}); 如何解决错误消息“ XMLHttpRequest无法加载跨源请求仅在AngularJS中支持HTTP?

如果这是用于本地开发,并且您正在使用Chrome,则需要使用几个参数来运行Chrome,以放松安全性,例如:

'C:Program Files (x86)GoogleChromeApplicationchrome.exe' --allow-file-access-from-files --disable-web-security解决方法

这是我的代码:

MyAppModule.factory(’EventData’,function($http,$log){ return {getEvent : function(successcb){ $http({method: ’GET’,url: ’./js/Services/products.json’}). success(function(data) {$log.info('success'); }). error(function(data) {$log.info('error'); });} };});

我在本地有一个简单的JSON文件,我正在尝试使用AngularJS的http方法读取它。我收到以下错误:

XMLHttpRequest无法加载文件:///C:/Users/Avraam/Documents/GitHub/AngularJS/app/js/Services/products.json仅HTTP支持跨源请求。angular.min.js:73错误:发生网络错误。

我怎么了 我没有使用任何服务器;我只是用Chrome打开索引文件。这是错误吗?如果要使用该http方法,应该使用服务器吗?

相关文章: