J'ai créé un asp.application net api qui lit les données d'un fichier JSON et les affiche dans un tableau. Lorsque je l'exécute à partir de Visual Studio, il lit avec succès les données et les affiche, mais après avoir téléchargé sur Azure, la table est vide.
Je l'ai stocké dans le dossier "jsondata" et l'appel se fait comme ceci:
var request = {
method: "get",
url: "../jsondata/data.json",
dataType: "json",
contentType: "application/json"
};
Tête:
<script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.5.0/angular.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css" integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp" crossorigin="anonymous">
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/assets/css/bootstrap.css">
<script src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
Corps:
<div ng-app="myApp"
ng-controller="myController">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>ID</th>
<th>Furniture Piece</th>
<th>Category</th>
<th>Price</th>
</tr>
</thead>
<tbody>
<tr ng-repeat="furniture in list">
<td>{{furniture.ID}}</td>
<td>{{furniture.Name}}</td>
<td>{{furniture.Type}}</td>
<td>{{furniture.Price}}</td>
</tr>
</tbody>
</table>
</div>
Script pour lire le fichier json avec angular:
<script>
var app = angular.module("myApp", []);
app.controller("myController",
function ($scope, $http) {
var request = {
method: "get",
url: "../jsondata/data.json",
dataType: "json",
contentType: "application/json"
};
$scope.arrFurniture = new Array;
$http(request)
.success(function (jsonData) {
$scope.arrFurniture = jsonData;
$scope.list = $scope.arrFurniture;
})
.error(function () {
});
});
</script>
Réponses:
1 pour la réponse № 1Pour servir des fichiers .json statiques à partir d'un service Azure App, vous devez ajouter le mimeMap suivant à votre web.config
fichier:
<?xml version="1.0"?>
<configuration>
<system.webServer>
<staticContent>
<mimeMap fileExtension=".json" mimeType="application/json" />
</staticContent>
</system.webServer>
</configuration>
Référence: Comment gérer des fichiers .json statiques à partir d'un site Web Windows Azure