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();
}
});