我在 JavaScript 中有以下代码(formdata),它在 Mozilla 和 Chrome 中正常工作。当我在IE 11中尝试它时,使用 ajax 不能很好地发布。成功函数被调用,但$_FILES
在服务器端为空。
file = _files[i][j];
if(j<_files[i].length){
if(file){
var data = new FormData();
data.append("uploadedimages", file);
console.log("formdata:"+data);
progressElement = $('#divimg_'+i+'_'+j);
progressElement.css('visibility','visible').hide().fadeIn('500');
$.ajax({
url: "<?php echo base_url();?>"+"upload/do_upload",
data: data,
cache: false,
contentType: false,
processData: false,
type: 'POST',
success: function(data){
console.log(data);
j++;
if(j<_files[i].length){
uploadmore(i,j);
}else{
i++;
uploadme(i,0);
}
},
xhr: function()
{
var xhr = new window.XMLHttpRequest();
xhr.upload.addEventListener( 'progress', function( e )
{
if( e.lengthComputable )
{
// Append progress percentage.
var progressValue = ( e.loaded / e.total ) * 100;
console.log( i + ':' + progressValue );
progressElement.find( 'input' ).val( progressValue ).change();
// Listen for clicks on the cancel icon.
$('#stopupload').click( function()
{
if( progressElement.hasClass( 'working' ) )
{
xhr.abort();
progressElement.fadeOut(500);
}
});
if( progressValue == 100 )
{
progressElement.removeClass( 'working' );
}
}
}, false);
return xhr;
}
});
}
else{
console.log("FILE ERROR!");
j++;
uploadmore(i,j);
}
}