gpt4 book ai didi

java - 如何在ajax中发送多部分请求?

转载 作者:太空宇宙 更新时间:2023-11-04 14:29:27 25 4
gpt4 key购买 nike

给定的代码我需要上传 zip 文件,因此我需要从 ajax 向服务器发送多部分请求。但是服务器获取请求为空值如何解决这个问题?有什么想法可以向服务器发送请求吗?

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() {
//window.location.href = clientURL + "/common/jsp/import.jsp";
var serverURL = "http://localhost:8080/bwsim/UploadScenario";
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");
}
}
});
}

最佳答案

您可以通过 jquery ajax form plugin 轻松实现.使用此插件,您可以通过 ajax 调用轻松发送额外的 $_POST 数据以及表单。

关于java - 如何在ajax中发送多部分请求?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26316556/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com