gpt4 book ai didi

javascript - struts2中如何通过ajax上传文件

转载 作者:行者123 更新时间:2023-12-03 05:21:34 26 4
gpt4 key购买 nike

<s:file name="excel" id="excel"/> 
function saveData(){
vald();
var postData = $("#fname").serializeArray();
$("#fname")[0].reset();
$('<div class="success-tog" >Processing...</div>').prependTo('body').delay(1000);
$.ajax({type: "POST",url: "",data: postData success: sucFunc()});

Script Code

}

最佳答案

您可以使用formdata上传代码或任何jquery文件上传插件 https://stackoverflow.com/a/204271/876739

你可以看这篇文章https://stackoverflow.com/a/41458116/876739

$(document).on('click', '#upload', function(e) {
e.preventDefault();
var fd = new FormData();
var file = $('#my_file')[0].files[0];
fd.append('file', file);
fd.append('userId', $('#userid').val());
console.log("hi");
$.ajax({
url: 'UploadPic',
data: fd,
type: "POST",
contentType: false,
processData: false,
success: function(dd) {
alert("sucessfully Uploaded")
}
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input type="file" id="my_file">
<input type="hidden" id="userid" />
<input type="button" id="upload" value="Upload" />

关于javascript - struts2中如何通过ajax上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41357194/

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