2010-07-23 54 views

回答

14

xhr.sendAsBinary()是非標準的。而是使用xhr.send(FormData),它確實創建了multipart/form-data請求,允許附加文件和任意表單數據。

var formData = new FormData(); 
formData.append(file.name, file); 

var xhr = new XMLHttpRequest(); 
xhr.open('POST', '/upload', true); 
xhr.onload = function(e) { ... }; 

xhr.send(formData); // multipart/form-data 

http://www.html5rocks.com/en/tutorials/file/xhr2/#toc-send-formdata

1

關鍵是使用sendAsBinary(body)而不是send(body)。查看您鏈接的頁面上的最新評論!

相關問題