I have got a HTML FORM with two fields a type text and input type file Fields
This is the below code
<form id="myForm" method="post">
First name: <input type="text" id="fname" name="fname"><br>
Files: <input type="file" id="files" name="files" multiple><br/>
</form>
<br><br><br>
<input type="button" value="Add To Container" class="addtocontainer">
<input type="button" value="Submit Ajax call " class="callAjax">
Once User fills up this fields , and Clicks on Add To Container Button , it will be added to a Array (User can add as many as forms to the array)
And finally he clicks on Submit button to insert all the contents of array to Database through Ajax call
This is my code
var newArr=[];
$(document).on("click", ".addtocontainer", function(event) {
var form = $('form')[0];
var formData = new FormData(form);
newArr.push(formData);
$("#fname").val('');
$("#files").val('');
});
$(document).on("click", ".callAjax", function(event) {
for(var i=0;i<newArr.length;i++)
{
console.log(newArr[i]);
}
});
In the callAjax event i am getting FomData empty when i am retrieving it through looping an array Could you please tell me if this is the right approach or not
This is my fiddle
serializeArray()?