1
当我使用jQuery提交表单时发生奇怪的事情。尽管我没有在表格中选取任何图像,但$_FILES
数组包含一个空值。如果我选择图像,则会有一个额外的空值。jQuery - FormData发送一个空的图像
以前有人看过这个吗?
Array
(
[item_image] => Array
(
[name] => Array
(
[0] =>
)
[type] => Array
(
[0] =>
)
[tmp_name] => Array
(
[0] =>
)
[error] => Array
(
[0] => 4
)
[size] => Array
(
[0] => 0
)
)
)
AJAX
$("#fileupload").submit(function(event)
{
//disable the default form submission
event.preventDefault();
//grab all form data
var formData = new FormData(this);
$.ajax({
url: 'ajax/add-item.php',
data: formData,
type: 'POST',
cache: false,
contentType: false,
processData: false,
success: function (data) {
alert(data);
if(data)
{
$("#fileupload > div.alert").text('Upload successful.');
$('html, body').animate({scrollTop : 0},700);
document.getElementById("#fileupload").reset();
}
}
});
});
您的日志中有任何错误? – Eric
不...没有错误。 – Ciprian
[错误] =>阵列 ( [0] => 4,好像你有错误,它说UPLOAD_ERR_NO_FILE 值:4;没有文件上传 – Eric