【发布时间】:2016-08-27 08:43:54
【问题描述】:
对于我正在开发的应用程序,我们有一个功能,我们在服务器端为对象生成报告,并在客户端的新选项卡中(暂时)打开它。
我正在使用URL.createObjectURL 函数为Blob 创建一个URL,该URL 由AJAX 调用的结果组成。但是,每当调用 $window.open(generatedFileUrl) 时,我都会收到 JavaScript 错误。
控制器:
(function() {
angular.module('app').controller('someCtrl', [
'$window', 'someSvc', controller
]);
function controller($window, someSvc) {
var vm = this;
vm.thing = {}; // How we get the object is unimportant for this question.
vm.printThing = printThing;
function printThing() {
someSvc.printThing(vm.thing.id, vm.someFlag)
.then(function(result) {
var file = new Blob([result], {type: 'application/pdf'});
var fileURL = URL.createObjectURL(file);
$window.open(fileURL);
});
}
}
)();
服务:
(function () {
angular.module('app').factory('someSvc', [
'$http', someSvc
]);
function someSvc($http) {
var service = {
printThing: function(thingId, someFlag) {
var args = {
'thingId': thingId,
'someFlag': someFlag
};
return $http.get('/Reports/SomeReport', { 'params': args });
}
};
return service;
}
})();
服务器端代码对这个问题并不重要。
问题:为什么在我的控制器代码中,我在 IE11 中收到错误消息0x80070005 - JavaScript runtime error: Access is denied.?另外,我可以通过什么方式避免 Access Is Denied 错误?
【问题讨论】:
标签: javascript angularjs pdf-generation