以下功能不起作用。我想上传多个文件&请求由ajax提交。内容类型出现“text / plain; charset = UTF-8”我想更改内容类型=“multipart / form-data” 以下功能如下所示.plz提供任何建议
function importNow(serverURL, parameters) {
document.body.style.cursor = "wait";
$.ajax({
url: serverURL,
data: parameters,
processData: false,
contentType: false,
type: "POST",
cache: false,
dataType: "text",
success: function(data) {
if ($.trim(data) === "Success") {
updateStatusMessage("success", "Import scenario successfully");
} else {
updateStatusMessage("failure", $.trim(data));
}
document.body.style.cursor = "default";
},
async: false
});
}
function importScenario() {
var serverURL = homeURL + "/runapp";
var parameters = "requestType=Import&subRequestType=importScenario&userName=" + userName ;
refButton = '<form id="importForm" 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()) {
parameters;
importNow(serverURL, parameters);
$(this).dialog("close");
}
},
'Cancel': function() {
$(this).dialog("close");
}
}
});
}
答案 0 :(得分:1)
您必须使用FormData
对象执行multipart/form-data
ajax请求
var parameters = new FormData();
parameters.append("requestType","Import");
parameters.append("subRequestType","importScenario");
parameters.append("userName",userName );
...
importNow(serverURL, parameters);