[英]how to load local json file in single page application with angularjs
I'm building a what called mini single page application which all the logic is in the client side and i'm using Angular for that. 我正在构建一个所谓的迷你单页应用程序,其所有逻辑都在客户端,而我正在为此使用Angular。 my problem is to load a JSON file which is not stored at any server but in my project tree - each time that i'm trying to load the file i'm getting 404.3 error code (tried with several browsers) - there is no issue with my call as i tried to call to a JSON file that stored on webserver and it worked wonderful - the only problem is when i'm trying to call to a local JSON.
我的问题是加载一个不存储在任何服务器上但存储在我的项目树中的JSON文件-每次尝试加载该文件时,我都会收到404.3错误代码(尝试使用多个浏览器)-没有问题与我的通话一样,因为我尝试调用存储在Web服务器上的JSON文件,并且效果很好-唯一的问题是当我尝试调用本地JSON时。 this is my call:
这是我的电话:
app.controller("myCtrl", function ($scope, $http) {
$http.get('/Data/names.json')
.success(function (data, status, header, config) {
console.log("file loaded");
console.log(data);
console.log(status);
console.log(header);
console.log(config);
})
.error(function (data, status, header, config) {
console.log("ERROR file didn't load");
//console.log(data);
//console.log(status);
//console.log(header);
//console.log(config);
})
}); });
solved by adding web.config file to my project with the following lines: 通过使用以下行将web.config文件添加到我的项目中来解决 :
<system.webServer> <staticContent> <mimeMap fileExtension=".json" mimeType="application/json" /> </staticContent> </system.webServer>
Solved by adding web.config file to my project with the following lines: 通过使用以下几行将web.config文件添加到我的项目中来解决:
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.