我是angularJS的新手,我正在尝试使用它从json文件中获取数据。当我运行程序时,控制台会读出404错误并且文件不存在。
这是我用来尝试检索json文件的角度。
var appLaptops = angular.module('appLaptops', []);
appLaptops.service("laptopsService", function ($http, $q) {
var deferred = $q.defer();
$http.get('json/laptops.json')
.then(function (data) {
deferred.resolve(data);
});
this.getLaptops = function () {
return deferred.promise;
}
})
appLaptops.controller('ctrlLaptops', function ($scope, laptopsService) {
var promise = laptopsService.getLaptops();
promise.then(function (data) {
$scope.laptop = data;
//For testing
console.log($scope.laptop);
})
});
下面我还将附上文件夹结构图片的链接以及错误读数。
答案 0 :(得分:0)
此问题与角度无关。您有404错误,因为IIS不知道如何处理public void Savefile() throws WriteException, IOException, BiffException {
WritableWorkbook workbook = null;
Stage stage = new Stage();
FileChooser fileChooser1 = new FileChooser();
File file = fileChooser1.showSaveDialog(stage);
System.out.println(file);
try {
File template = new File("C:\\Users\\Bart\\Desktop\\Factuur.xlsx");
Workbook workbook1 = Workbook.getWorkbook(template);
WritableWorkbook copy = Workbook.createWorkbook(file, workbook1);
WritableSheet sheet = copy.getSheet(0);
jxl.write.Label label = new jxl.write.Label(0, 13, "A label record");
sheet.addCell(label);
} catch (IOException ex) {
Logger.getLogger(AlatasController.class.getName()).log(Level.SEVERE, null, ex);
} finally {
workbook.write();
workbook.close();
}
}
文件。
有两种方法可以解决这个问题:
更新web.config以让IIS了解此类文件的内容类型(在QueryLars的评论中提到):
$http.get of json file always returns 404