0

次のエラーが表示されます。

[Exception... "The operation is insecure." code: "18" nsresult: "0x80530012 (SecurityError)" location: "http://code.jquery.com/jquery-1.9.1.js Line: 2257"]

コードを調べてみましたが、例外が何であるかがわかりません。簡単に言えば、次のような Angularjs オブジェクトが渡されます。

replyForm = {

    body: someString,

    // Gets the file from some input
    fileAttachment: event.target.files[0]

}

そして、replyFormオブジェクトを受け取り、それを次のような関数に渡そうとする関数があります:

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);
};

私の fileAttachment が Angularjs でどのように設定されるかを確認したい場合は、以下を参照してください。

.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];
                    });

                });
            }
        };
    });

プロパティの1つにファイルが添付されたオブジェクトを渡すことの何が問題だったのか、誰かが教えてくれたら素晴らしいでしょう。jQuery が dom に対して何かを行おうとすると、セキュリティ例外が発生するという問題があるようですが。

4

1 に答える 1

1

レイヤーをはがした後、参照している行はinput.valueファイル入力フィールドに設定しようとしています。これはセキュリティ上の理由から不可能です。ファイル入力フィールドの値は、ユーザーが選択する必要があり、JavaScript では設定できません。

ファイルをアップロードする必要がある場合、そのためのファイル アップロード フィールドは必要ありません。FormDataオブジェクトがそれを処理できます。これらの行に沿った何かが機能するはずです:

var sendForm = function(replyForm){
  var fd = new FormData($("#myform"));
  fd.append("fileInput", replyForm.fileAttachment);
  ...
  $.ajax({..., data: fd});

FormDataFirefox 4、Chrome 7、IE 10 以降でサポートされています。

于 2013-10-27T08:15:34.363 に答える