我正在使用FormData上传文件。同时,我也想发送一些其他数据的数组。
当我只发送图片时,它可以正常工作。当我向formdata附加一些文本时,它也可以正常工作。但是当我尝试连接下面的“tags”数组时,其他所有内容都可以正常工作,但是没有数组被发送。
是否有关于FormData和添加数组的已知问题?
实例化formData:
formdata = new FormData();
我创建的数组。Console.log显示一切正常。
// Get the tags
tags = new Array();
$('.tag-form').each(function(i){
article = $(this).find('input[name="article"]').val();
gender = $(this).find('input[name="gender"]').val();
brand = $(this).find('input[name="brand"]').val();
this_tag = new Array();
this_tag.article = article;
this_tag.gender = gender;
this_tag.brand = brand;
tags.push(this_tag);
console.log('This is tags array: ');
console.log(tags);
});
formdata.append('tags', tags);
console.log('This is formdata: ');
console.log(formdata);
我该如何发送它:
// Send to server
$.ajax({
url: "../../build/ajaxes/upload-photo.php",
type: "POST",
data: formdata,
processData: false,
contentType: false,
success: function (response) {
console.log(response);
$.fancybox.close();
}
});