Jquery ajax 页面根据 post 请求自动重定向
Jquery ajax page is automatically redirecting on post request
尝试通过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.');
}
});
}
其实我是把上传的文件名写在document.所以我删除了下面的行
document.write(imageFiles.files[i].name);
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");
尝试通过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.');
}
});
}
其实我是把上传的文件名写在document.所以我删除了下面的行
document.write(imageFiles.files[i].name);
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");