这里我需要在表单提交时设置contenttype="multipart/form-data"
,但它失败了,它分配了contenttype="text/html"
如何更改?
refButton = '<form id="importForm" action="http://localhost:8080/bwsim/UploadScenario" class="userInputForm" enctype="multipart/form-data">' +
'<input id="file" name="file" type="file" />' +
'</form>';
document.getElementById("popupDiv").innerHTML = refButton;
$("#popupDiv").dialog({
title: "Import Scenario",
draggable: true,
bgiframe: true,
modal: true,
width: 500,
heigth: 100,
show: {effect: 'blind', duration: 500},
hide: {effect: 'fade', duration: 1000},
zIndex: 1000,
buttons: {
'Upload': function() {
if ($("#importForm").valid()) {
document.forms["importForm"].submit();
$(this).dialog("close");
}
},
'Cancel': function() {
$(this).dialog("close");
}
}
});
最佳答案
its fail it's assign contenttype="text/html" how to change?
不,不是。
您的表单没有 method
属性,因此默认为 GET。
GET 请求没有请求正文,因此没有内容来描述其内容类型。
将 method="POST"
添加到表单开始标记。
关于javascript - 如何在表单中设置内容类型?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26340344/