即使部署到服务器上,AngularJS应用程序也不能读取本地文本文件
AngularJS application cant read local text file even after deployed on server
我的应用程序中有4个文件(在同一目录中),部署在IIS上-
- home。
- Angular.js
- data.txt
- 网络。配置(默认文件由IIS自动生成)
我想在'home.html'上显示'data.txt'的内容。相同的代码运行在[Plunker][1]
这个'home.html'文件的代码如下:
<!DOCTYPE html>
<html>
<head>
<title>nitin</title>
<script src="angular.js" type="text/javascript"></script>
<script type="text/javascript">
var nameSpace = angular.module("app", []);
nameSpace.controller("GuitarFunction", function ($scope) {});
</script>
</head>
<body ng-app="app">
<div ng-controller="GuitarFunction">
<ng-include src="'data.txt'">
</ng-include>
</div>
</body>
</html>
http://plnkr.co/edit/8aBJsqzV07AweDk4PAcG?p =预览
网站需要托管在一个web服务器(IIS, Apache),所以它可以通过http/https提供。
浏览器安全措施将阻止脚本加载外部资源,如果协议是file://。
如果您在IIS中托管C:'webapp,例如端口5000,您需要将浏览器定向到http://localhost:5000/index.html,而不是C:'webapp'index.html.
您需要在web中包含覆盖。如果你的网站没有服务器代码,那么你的覆盖只是应用程序的名称,如
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode"/>
</handlers>
<rewrite>
<rules>
<rule name="DynamicContent">
<conditions>
<add input="{{REQUEST_FILENAME}}" matchType="IsFile" negate="True"/>
</conditions>
<action type="Rewrite" url="server.js"/>
</rule>
</rules>
</rewrite>
相关文章:
- DOM范围克隆也不能免受DOM更改的影响
- 嵌入式谷歌地图仅在IE上加载,但既不能在Mozilla Firefox上加载,也不能在Google Chrome上加载
- RubyonRails应用程序不能包含样式表也不能包含js
- Jquery-Mobile:Changepage不起作用,如果我指定了pageid,我也不能将数据传递到另一个页面
- 既不能使用JavaScript也不能使用jQuery设置隐藏表单字段
- 即使链接了最新的Jquery库,Jquery也不能在页面上工作
- 即使导入了Jquery函数,也不能定义它
- 我不能直接访问对象中的字段,也不能使用getter函数访问
- 即使在关闭后也不能从引导模式中清除错误消息
- 不能使用jquery禁用锚标签.没有"disabled&;也不能在ajax调用()期间使用e.p preven
- Javascript表格单元格值读取器不能从.net Repeater获取值
- 谷歌地图不能点击,也不能在Magento主页上平移
- Ng-if和ng-class-even/odd不能很好地一起工作,也不能得到期望的结果
- 即使加载了UJS, Rails DELETE调用也不能工作
- 即使添加了很多延迟,Focus在IE中也不能工作
- 从文件中的JSON数组中读取,不能访问该数组或将其压入其中
- 即使部署到服务器上,AngularJS应用程序也不能读取本地文本文件
- Javascript在chrome中工作,但即使在安全模式下也不能在Firefox中工作
- jQuery在firefox上不能很好地工作,在Safari上也不能工作
- Google Map Custom InfoWindow's Tail不能移动,也不能移除下拉阴影