gpt4 book ai didi

javascript - Jquery ajax 页面在发布请求时自动重定向

转载 作者:行者123 更新时间:2023-11-29 21:39:15 27 4
gpt4 key购买 nike

尝试通过ajax上传多个文件,但上传后自动重定向到另一个空白页面,只显示上传文件的名称

下面是html标签

这是javascript函数

function upload(){

var projectId = document.getElementById("projectId").children[0].value;
var referenceNo = document.getElementById("referenceNo").value;
var createdBy = document.getElementById("initiatedBy").value;
if(projectId == null)
{
alert('Please select project first');
return;
}

var formData = new FormData();
var imageFiles = document.getElementById("fileId"),
filesLength = imageFiles.files.length;
for (var i = 0; i < filesLength; i++) {
document.write(imageFiles.files[i].name);
formData.append('files',imageFiles.files[i]);

}

$("#fileId").val('');

var methodName = 'uploadBPMFiles';
formData.append('refId',referenceNo);
formData.append('projectId',projectId);
formData.append('uploadedBy',createdBy);
formData.append('processType','EOT');

$.ajax({
url: webUrl+methodName,
data: formData,
processData: false,
type: 'POST',
cache:false,
dataType: "json",
contentType: false,
enctype : "multipart/form-data",
success: function(responseData) {
alert('success');
/**console.log('responseData: '+responseData);
console.log('responseData: '+responseData);
var obj = (responseData.downloadURLs);
console.log(obj)
for (var i in obj) {
console.log(obj[i]);
//$("response")<a href="http://www.test.com/b6">World</a>
//$('#response').append('<a href="'+obj[i]+'">Link</a>');

}
//console.log($('#response').val());
//console.log('end');
**/
}
,
error: function (responseData) {
console.log('POST failed.');
}
});

最佳答案

Note: as document.write writes to the document stream, calling document.write on a closed (loaded) document automatically calls document.open which will clear the document.

document.write(imageFiles.files[i].name);将清除您的文档。您必须附加一个带有文件名的新元素才能在您的站点上显示它们。为此,您可以使用 jQuery 创建一个新元素

$("<span>").text(imageFiles.files[i].name).appendTo("body");

关于javascript - Jquery ajax 页面在发布请求时自动重定向,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33687745/

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