Angularjs 访问本地 json 文件 [英] Angularjs access local json files

查看:25
本文介绍了Angularjs 访问本地 json 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是 angularjs 的新手,我一整天都在网上搜索,只是为了找到从本地 json 文件获取数据的解决方案,而不必为我的 web 应用程序使用本地主机.不幸的是,我还没有找到任何.我尝试使用 $http.get 但我收到 Cross Origin * 错误.

有没有其他方法可以让我从本地 json 文件中获取数据而不必在本地托管我的 web 应用程序?

angularjs 是否有任何其他功能可以从本地 json 文件中获取数据而无需使用其 $http.get?

解决方案

您需要将您的应用程序部署到某个 http 服务器,最简单的方法是使用 node,这里是示例 https://www.npmjs.org/package/http-server,或者您可以更改浏览器安全设置.>

I am new to angularjs and I've been searching on the web the whole day just to find a solution in getting data from a local json file without having to use a localhost for my webapp. Unfortunately, I haven't found any. I tried using $http.get but I get Cross Origin * error.

Is there no other way that I could get the data from my local json file without having to locally host my webapp?

Does angularjs have any other function to get data from local json files without having to use its $http.get?

解决方案

You need to deploy your application to some http server, the easiest way to this is using node, here is the exmaple https://www.npmjs.org/package/http-server, or you can change you browser security settings.

这篇关于Angularjs 访问本地 json 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆