I ran into a problem with AJAX and FromData due to lack of experience. I try to get all values from the dinamic fields (users can add new input fileds as many as they want) put them in different arrays, then put it in the FormData. After all I plan to send them using AJAX to another file where to put everything from FormData to data base with php.
So, please, give me a hint how to send that FormData via AJAX (do I need to serialize it or put in a JSON string) and how to get the values from it as $_POST['']
.
Currently I did that code
var mySubTasks = [];
$('.subTasky').each(function(){
mySubTasks.push({
id: $(this).attr('id'),
title: $(this).children('.currentInput').val(),
comment: $(this).children().children('.currentInputCom').val(),
img: $(this).children('.taskPhoto').prop("files")[0]
});
});
var myHeaders = [];
$('.subHeader').each(function(){
myHeaders.push({
header: $(this).children('.listInput').val()
});
});
var mySubSub = [];
$('.subsub').each(function(){
mySubSub.push({
id: $(this).attr('id'),
title: $(this).children('.currentInput').val(),
comment: $(this).children().children('.currentInputCom').val()
});
});
var myPrime = [];
$('#mainTaskBox').each(function(){
mySubSub.push({
title: $(this).children('.listPrTitle').val(),
comment: $(this).children().children('.listPrCom').val(),
img: $(this).children().children('.taskPhoto').prop("files")[0]
});
});
var formData = new FormData();
formData.append('mySubTasks', mySubTasks);
formData.append('myHeaders', myHeaders);
formData.append('mySubSub', mySubSub);
formData.append('myPrime', myPrime);
console.log(formData);
What should I do next.