[英]Why doesn't this Plnkr work when I download it?
I'm new to Angular.js and have been playing around with it on Plnkr here http://plnkr.co/edit/jR9VfaEhjUfY0vN7mfWd 我是Angular.js的新手,并且一直在Plnkr上玩它http://plnkr.co/edit/jR9VfaEhjUfY0vN7mfWd
The Plnkr Preview shows the Tabs and Partials loading fine but when I download it my computer only the Tabs work, why aren't the Partials displaying? Plnkr预览显示选项卡和部分加载正常,但当我下载它我的计算机只有选项卡工作,为什么部分不显示? Hope this screenshot explains my predicament:
希望这个截图解释我的困境:
Thanks 谢谢
You need to fetch the page using a web server so there is no "Access-Control-Allow-Origin" violation. 您需要使用Web服务器获取页面,因此没有“Access-Control-Allow-Origin”违规。 When a script from
example1.com
tries to make AJAX request on example2.com
, browsers first check if example2.com
allows access from other website. 当
example1.com
的脚本尝试在example2.com
上发出AJAX请求时,浏览器首先检查example2.com
允许从其他网站访问。 This is done by reading Access-Control-Allow-Origin
header of example2.com
. 这是通过读取
example2.com
Access-Control-Allow-Origin
标头来完成的。 Most websites normally don't allow AJAX access. 大多数网站通常不允许AJAX访问。
In your case, the origin is file:///...
which won't be setting the Access-Control-Allow-Origin
header and since the default is to block the request, you get the error. 在您的情况下,原点是
file:///...
它不会设置Access-Control-Allow-Origin
标头,并且由于默认是阻止请求,您会收到错误。
To get past this, do the following (Make sure you have ruby or python installed) - 要完成此操作,请执行以下操作(确保安装了ruby或python) -
cd
command to switch to your project directory ( tutorial ) cd
命令切换到项目目录( 教程 ) Type either of the command 输入任一命令
python -m SimpleHTTPServer for python
or 要么
ruby -run -e httpd -- -p 8000 . for ruby.
This will run a basic HTTP server at port 8000. The HTTP server will allow access to files in the directory you have run the command from. 这将在端口8000上运行基本HTTP服务器.HTTP服务器将允许访问您运行命令的目录中的文件。 So if you have, for eg,
index.html
in the directory, you could do http://localhost:8000/index.html
因此,如果您在目录中有
index.html
,则可以执行http://localhost:8000/index.html
Looking at the screenshot, you can do this - 看截图,你可以这样做 -
run 跑
cd C:/Users/Jonny/Desktop/plunker
start server 启动服务器
python -m SimpleHTTPServer
http://localhost:8000/index.html#/invoices
in your browser. http://localhost:8000/index.html#/invoices
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.