2011-01-26 19 views
0

私はajaxファイルアップロードモジュールを作成しようとしています。場所で[1]私はあなたが参照元を与えることができる、セキュリティエラーSecurity error" code: "1000を取得する必要があり、なぜ、次のコードスニペットでなぜ私のajaxファイルアップローダが正しく動作しないのですか?

//create the form for uploading the file the ajax file 
FileUploader.prototype.createForm = function() { 
    // create the new form 
    var form = document.createElement('form'); 
    form.id = this.form_id; 
    form.action = this.url; 
    form.method = 'post'; 
    form.enctype = 'multipart/form-data'; 
    form.target = 'file_upload_iframe'; 

    // try to create a file type of input failed at [1] 
    /* var input_file = document.createElement('input'); 
    input_file.type = 'file'; 
    input_file.name = this.name; 
    input_file.value = this.file; [1] */ 

    // try to clone the input file but failed to insert it to the old form[2] 
    // or the new form [3] either 
    var input_file = document.getElementById('userfile'); 
    var new_input_file = document.cloneNode(true); 
    // document.getElementById('file_upload').appendChild(new_input_file); [2] 
    new_input_file.id = ''; 

    form.appendChild(new_input_file); // [3] 
    document.body.appendChild(form); 
    return form; 
}; 
  1. を見てください?

  2. 私はnew_input_fileを新しい作成されたフォーム[3]に追加したり、新しいクローンnew_input_fileを古いフォーム([2])に追加することができませんでしたか?

ありがとう。

答えて

0

文書全体を複製しようとしましたが、意味がありません。何が必要なコードです:

var new_input_file = input_file.cloneNode(true); 
とにかく

、入力タイプのファイルのvalue明らかなセキュリティ上の理由から、読み取り専用であるので、これは新しいフォームに実際の入力を追加して、「克服」する唯一の方法:

form.appendChild(input_file); 

ファイルを保存する必要があります。 (試していない)

+0

ありがとう。ああ、私はコードを再チェックすべきです、実際には** input_file **だと思っていましたが、存在しない答えを見つけるのに30分を記録して投資していません。 – Jichao

+0

@ Jic歓声、時にはあなたが必要とするのは目の新鮮なセットです。 :) –

+0

約8時間私のノートブックの前に置いた後....私の頭が台無しにされている...:) – Jichao

0

jqueryを使用してDOMを操作することはできませんか?

var input = $('<input>'); // create your element 
input.append($('#userfile').clone()); // append something