I have issue that Ajax request to server and I want to get my all form data and submit it to server. Problem is when I using new FormData(form)
is returning an empty object. I done this work before my previous projects and it worked fine. But why not working this time?. I know about .serializeArray
but I don't want to use this because of some reasons. The reason is I want to add some files and want to push it to the server.
jquery-version: 3.4.0
Form:
<form id="myForm">
<input type="email" name="username"/>
<input type="password" name="password"/>
<button type="button" id="btn">Submit</button>
</form>
Script:
$(document).ready(function () {
$('#btn').on('click', function () {
let formData = new FormData($('#myForm')[0]);
console.log(formData);
});
})