我正在使用像这样的ajax上传文件:
var data = new FormData();
jQuery.each(files, function(key, value)
{
data.append(key, value);
});
jQuery.ajax({
url: "<?php echo JURI::base().'modules/xxx/ajax_upload.php' ?>",
type: 'POST',
data: data,
cache: false,
dataType: 'json',
processData: false, // Don't process the files
contentType: false, // Set content type to false as jQuery will tell the server its a query string request
success: function(data)
{
if(typeof data.error === 'undefined')
{
// Success so call function to process the form
//submitForm(event, data);
}
else
{
// Handle errors here
console.log('ERRORS: ' + data.error);
}
},
error: function(jqXHR, textStatus, errorThrown)
{
// Handle errors here
console.log('ERRORS: ' + textStatus);
// STOP LOADING SPINNER
}
});
在控制台中我看到图像已发送,但在ajax_upload.php中我无法获取文件,尝试使用:
print_r($_FILES);
print_r($_POST);
并返回空数组,表单有enctype="multipart/form-data"