Would you like to submit some forms at the same time with FormData ?
For example, each product will have sizes and images. I would like to separate each product in an array and send it to the PHP page at the same time, so I can go through them with a foreach and make the registration.
I tried this way, but it mixes the data of all products, instead of separating:
var dados = new FormData();
$('.copiar-elemento').each(function() {
$(this).find("select[name*='tamanho']").each(function(index, element) {
dados.append('cores[tamanhos][]', element.value);
});
$(this).find('input:file').each(function(index, element) {
dados.append('cores[imagens][]', element.files[0]);
});
});
$.ajax({
url: $('#form-produto').attr('action'),
type: 'POST',
data: dados,
dataType: 'json',
processData: false,
contentType: false,
cache: false,
success: function(data) {
console.log(data);
}
});