传递带有附件的jQuery时出现安全异常0x80530012. AngularJS [英] Security Exception 0x80530012 when passing jQuery with attached file. Angularjs
问题描述
我遇到以下错误:
[Exception... "The operation is insecure." code: "18" nsresult: "0x80530012 (SecurityError)" location: "http://code.jquery.com/jquery-1.9.1.js Line: 2257"]
我尝试查找代码,但是找不到异常.简而言之,我传递了一个类似以下内容的Angularjs对象:
I've tried to look up the code but I can't find what the exception is. Simply put I have an Angularjs object being passed that looks like:
replyForm = {
body: someString,
// Gets the file from some input
fileAttachment: event.target.files[0]
}
我有一个函数,它可以接收ReplyForm对象,并尝试将其传递给某些函数,如下所示:
And I have a function that recieves the replyForm object and tries to pass it into some function like so:
var exe = function (replyForm){
//This is the line that causes my mozilla security exception to go off
sendForm(replyForm);
};
var sendForm = function(replyForm){
// This is when I get the security exception
$('input.fileInput').val(replyForm.fileAttachment);
};
如果您想了解如何在Angularjs中设置我的fileAttachment,请参阅以下信息:
If you want to see how my fileAttachment gets set in Angularjs, please refer bellow:
.directive('ngFile',function(){
return {
scope: {
ngFile: '='
},
link: function(scope, el, attrs){
el.bind('change', function(event){
scope.$apply(function(){
scope.ngFile = event.target.files[0];
});
});
}
};
});
如果有人能告诉我传递带有附加到其属性之一的文件的对象有什么问题,那就太好了.尽管看来jQuery尝试对dom进行操作会产生一些安全异常,这是一个问题.
It would be great if anyone could tell me what was wrong with passing an object with a file attached to one of it's properties. Though it seems there is an issue with jQuery trying to do something to the dom which creates some security exception.
推荐答案
剥离图层后,您要引用的行将尝试在文件输入字段上设置input.value
.出于安全原因,这是不可能的.文件输入字段的值必须由用户选择,不能由JavaScript设置.
After you peel away the layers, the line you are referring to is trying to set input.value
on a file input field. This isn't possible for security reasons. The value of a file input field has to be selected by the user, it cannot be set by JavaScript.
If you need to upload a file, you don't need a file upload field for that - a FormData
object can handle that for you. Something along these lines should work:
var sendForm = function(replyForm){
var fd = new FormData($("#myform"));
fd.append("fileInput", replyForm.fileAttachment);
...
$.ajax({..., data: fd});
从Firefox 4,Chrome 7和IE 10开始支持
FormData
.
FormData
is supported starting with Firefox 4, Chrome 7 and IE 10.
这篇关于传递带有附件的jQuery时出现安全异常0x80530012. AngularJS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!