我試圖在summernote中將圖像上傳到服務器。下面的腳本是成功提交表單,但文件沒有收到後端。我在這裏做錯了什麼?動態表單不提交文件
var edit = function() {
$('.click2edit').summernote({
focus: true,
onImageUpload: function(files, editor, welEditable) {
sendFile(files[0],editor,welEditable);
}
});
};
function sendFile(file,editor,welEditable) {
alert(file.size);
var iframe = $('<iframe name="postiframe" id="postiframe" style="display: none" />');
$("body").append(iframe);
alert("1");
var form = $('#theuploadform');
form.attr("action", "UploadServlet");
form.attr("method", "post");
form.attr("enctype", "multipart/form-data");
form.attr("encoding", "multipart/form-data");
form.attr("target", "postiframe");
form.attr("file", file);
form.submit();
alert("2");
$("#postiframe").load(function() {
iframeContents = $("#postiframe")[0].contentWindow.document.body.innerHTML;
return iframeContent;
});
return false;
}
@rkanawo有沒有解決我的問題。限制是我只會在這個位置獲取文件。 – RajnikantDixit
必須在沒有用戶交互的情況下獲取文件的唯一方法是在客戶端計算機上預安裝軟件,使用ActiveX控件(僅適用於IE)或Java Applet運行您的頁面,但存在一些安全問題。 http://docs.oracle.com/javase/tutorial/deployment/applet/security.html – rkawano