错误:无法在“XMLHttpRequest"上执行“发送":无法加载“文件":AngularJS SPA [英] Error: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file' : AngularJS SPA

查看:48
本文介绍了错误:无法在“XMLHttpRequest"上执行“发送":无法加载“文件":AngularJS SPA的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对 Angular SPA 非常陌生,这是我第一次通过谷歌搜索获得代码并尝试运行.但是我在控制台中遇到了一些错误.我不知道为什么,我发现了以下控制台错误列表:

<块引用>

XMLHttpRequest 无法加载file:///C:/Users/hp/Downloads/single-page-app-angularjs-master/home.html.仅协议方案支持跨源请求:http、数据、chrome、chrome 扩展、https、chrome 扩展资源.

错误:无法在XMLHttpRequest"上执行发送":加载失败'file:///C:/Users/hp/Downloads/single-page-app-angularjs-master/home.html'.XMLHttpRequest 无法加载file:///C:/Users/hp/Downloads/single-page-app-angularjs-master/about.html.跨源请求仅支持以下协议方案:http、数据、chrome、chrome 扩展、https、chrome 扩展资源.

错误:[$compile:tpload]http://errors.angularjs.org/1.3.3/$compile/tpload?p0=home.html

<html lang="zh-cn"><头><meta charset="UTF-8"><title>使用 Angularjs 的单页 Web 应用</title><script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js"></script><script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.3/angular-route.min.js"></script><script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script><link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css"><script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script><script src="script.js"></script><body ng-app="single-page-app"><div ng-controller="cfgController"><div><nav class="navbar navbar-inverse" role="navigation" style="padding-left:130px;"><ul class="nav navbar-nav"><li class="active"><a href="#/">Home<span class="sr-only">(current)</span></a></li>;<li><a href="#/about">关于我们</a></li><li><a href="#/about">阅读教程</a></li></nav>

<br/><div ng-view class="jumbotron"></div>

</html>

解决方案

在 Windows 上:

chrome.exe --allow-file-access-from-files

chrome.exe --allow-file-access-from-files --disable-web-security

在 Mac 上:

open/Applications/Google\ Chrome.app/--args --allow-file-access-from-files

I'm very new to Angular SPA and for the first time I get a code by Googling and try to run. But I get some errors in Console. I couldn't figure out why, I found list of following Console errors:

XMLHttpRequest cannot load file:///C:/Users/hp/Downloads/single-page-app-angularjs-master/home.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

Error: Failed to execute 'send' on 'XMLHttpRequest': Failed to load 'file:///C:/Users/hp/Downloads/single-page-app-angularjs-master/home.html'. XMLHttpRequest cannot load file:///C:/Users/hp/Downloads/single-page-app-angularjs-master/about.html. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.

Error: [$compile:tpload] http://errors.angularjs.org/1.3.3/$compile/tpload?p0=home.html

<!doctype html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Single page web app using Angularjs</title>


<script src="http://ajax.googleapis.com/ajax/libs/angularjs/1.3.3/angular.min.js"></script>
 <script src="http://cdnjs.cloudflare.com/ajax/libs/angular.js/1.3.3/angular-route.min.js"></script>
  <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  <link rel="stylesheet" href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/css/bootstrap.min.css">
  <script src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.1/js/bootstrap.min.js"></script>
  <script src="script.js"></script>


</head>
<body ng-app="single-page-app">
  <div ng-controller="cfgController">
  <div>
  <nav class="navbar navbar-inverse" role="navigation" style="padding-left:130px;">
         <ul class="nav navbar-nav">
        <li class="active"><a href="#/">Home<span class="sr-only">(current)</span></a></li>
        <li><a href="#/about">About us</a></li>
        <li><a href="#/about">Read tutorial</a></li>
      </ul>
</nav>
</div>
  <br/>

  <div ng-view class="jumbotron"></div>
  </div>
</body>
</html>

解决方案

On Windows:

chrome.exe --allow-file-access-from-files

or

chrome.exe --allow-file-access-from-files --disable-web-security

On Mac:

open /Applications/Google\ Chrome.app/ --args --allow-file-access-from-files

这篇关于错误:无法在“XMLHttpRequest"上执行“发送":无法加载“文件":AngularJS SPA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
前端开发最新文章
热门教程
热门工具
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆