2012-04-25 21 views
0

dojoでファイルをアップロードするためのコードが必要です。 特にajax呼び出しとそのボタン作成、およびそのURLはデータベースに格納されなければなりません。私は、次のコードを使用しますが、それは働いていない:dojoで画像をアップロードするためのコードが必要

function uploadPicture() 
{ 
    alert("yes"); 
    var xhrArgs = { 
     url:"/service/ajax/uploadPictureToOption/",     
     form: dojo.byId("optionsForm"), 
     handleAs: "json", 
     content :{}, 
     load: function(response, ioArgs){ 
      if (response == "failed") 
      { 
       alert("Failed"); 
       window.location.reload(); 
      } 
      else if (response == "success") 
      { 
       window.location.reload(); 
      } 
      else 
      { 
       alert("Successfully deleted"); 
       window.location.reload(); 
      } 
     }, 
    } 
    var deferred = dojo.xhrPost(xhrArgs); 
} 
+0

まで、HTML5をサポートするdoesntのIEので、移動するための方法は非常にStackOverflowされていないで、なぜあなたの質問は、Pythonでタグ付けされましたか? – subiet

答えて

0

ファイルアップロードのためにあなたのアイデアを開始するために道場(AKA AJAX [プレーンテキストのみをhanddles])のXHRモジュールを使用して、現在IMPOSIBLEです。 あなたができる最も近い考えられることは、フォームを非表示のiframeにサブミットすることです。あなたのファイルであるという仮定を作る

<form method=”post” action=”formProcess.php” target=”hiddenIFrame”> 
<input type=”file” name=”test” /> 
<input type="submit" value="Submit"> 
</form> 

<iframe style=”width:0px;height:0px;border:0px;” name=hiddenIFrame /> 

「非表示のiframeを提出する」とあなたはまた、Googleで検索することができます

+0

ありがとうございます..情報...私は隠されたiframeの概念について私に詳細を送っています。私はそれに新しいです – Mowgli

1

EDIT

非表示のiframeのコードはこのようなものでなければなりませんバイナリ、それ以外はMoz MDN - File.getAsBinary を参照してください。FormData (xhr2)を任意に使用できます。 のIFrameは、完全なコードを尋ねるIE10

var xhr=(window.XMLHttpRequest && new window.XMLHttpRequest()), 
    input = dojo.byId('inputelementId') 
    boundary = "---------------------------" + (new Date).getTime(), 
    message = "" 
xhr.open("POST", this.getUrl()); 
xhr.setRequestHeader("Content-Type", "multipart/form-data; boundary=" + boundary); 
//  if(input.files.length > 1) { 
    message += "--" + boundary + "\r\n" 
     + 'Content-Disposition: form-data; name="' + input.name + '";' 
     + ' filename="'+ (input.files ? input.files[0].name : input.value) + '"' + EOL; 
    message += "Content-Type: application/octet-stream" + "\r\n" + "\r\n"; 
//  } 
if(!!xhr.sendAsBinary) { 
     xhr.send(message + input.files[0].getAsBinary()) 
} else { 
    // here is the kicker; IE does not support neither FileData nor AsBinary 
     var fobj = new ActiveXObject("Scripting.FileSystemObject"), 
      fd = fobj.OpenTextFile(input.value, 1); 
     xhr.send(message + fd.ReadAll()); 
     fd.Close(); 
} 
+0

非常に私のために非常に役立ってくれてありがとう...... – Mowgli

+0

あなたdojox.form .uploaderそれはいくつかの制限があり、私たちが話していないdojoxの枝です:) – mschr

関連する問題